Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): render Layout children as a content shorthand (no more blank shell) (#3143)

Joey58538220a7dd
diff --git a/.changeset/layout-children-as-content.md b/.changeset/layout-children-as-content.md
new file mode 100644
index 0000000000..ce52620aad
--- /dev/null
+++ b/.changeset/layout-children-as-content.md
@@ -0,0 +1,12 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `<Layout>…</Layout>` no longer renders a blank page. `Layout` is
+slot-driven (`content`/`header`/`start`/`end`/`footer`), and the natural nested
+form `<Layout><LayoutContent /></Layout>` previously type-checked and built
+green while dropping its children at runtime — an empty shell. Children now
+render as a shorthand for the `content` slot (`<Layout>{main}</Layout>` is
+equivalent to `<Layout content={main} />`), matching how `Card` and `Section`
+accept content; an explicit `content` prop still wins when both are provided.
+@josephfarina
diff --git a/packages/core/src/Layout/Layout.doc.mjs b/packages/core/src/Layout/Layout.doc.mjs
index c28c5ef340..1f663130c9 100644
--- a/packages/core/src/Layout/Layout.doc.mjs
+++ b/packages/core/src/Layout/Layout.doc.mjs
@@ -29,7 +29,8 @@ export const docs = {
{
name: 'content',
type: 'ReactNode',
- description: 'Main content area (center).',
+ description:
+ 'Main content area (center). Children passed to `<Layout>` render here too — `<Layout>{main}</Layout>` is shorthand for `<Layout content={main} />`.',
slotElements: [
{
__element: 'LayoutContent',
diff --git a/packages/core/src/Layout/Layout.tsx b/packages/core/src/Layout/Layout.tsx
index fe4fad7b71..cf6f7ded2f 100644
--- a/packages/core/src/Layout/Layout.tsx
+++ b/packages/core/src/Layout/Layout.tsx
@@ -157,6 +157,16 @@ export interface LayoutProps extends Omit<BaseProps, 'content'> {
* Inline styles to apply to the root element.
*/
style?: React.CSSProperties;
+
+ /**
+ * Children are a shorthand for the `content` slot:
+ * `<Layout>{main}</Layout>` is equivalent to `<Layout content={main} />`.
+ * The surrounding zones (`header`/`start`/`end`/`footer`) stay explicit
+ * props. If both `content` and `children` are provided, `content` wins.
+ * Accepting children keeps the natural `<Layout>…</Layout>` form from
+ * rendering a blank shell.
+ */
+ children?: ReactNode;
}
/**
@@ -222,6 +232,7 @@ function AreaProvider({
* ```
*/
export function Layout({
+ children,
content,
contentWidth,
defaultHasDividers,
@@ -237,6 +248,9 @@ export function Layout({
style,
}: LayoutProps) {
const isFill = height === 'fill';
+ // Children are a shorthand for the content slot; an explicit `content` prop
+ // wins when both are provided.
+ const resolvedContent = content ?? children;
const dividerCtxValue = useMemo(
() => (defaultHasDividers != null ? {defaultHasDividers} : null),
@@ -287,7 +301,7 @@ export function Layout({
)}>
<AreaProvider area="start">{start}</AreaProvider>
<div {...stylex.props(...stackItem({size: 'fill'}))}>
- <AreaProvider area="content">{content}</AreaProvider>
+ <AreaProvider area="content">{resolvedContent}</AreaProvider>
</div>
<AreaProvider area="end">{end}</AreaProvider>
</div>
diff --git a/packages/core/src/Layout/__tests__/childrenAsContent.test.tsx b/packages/core/src/Layout/__tests__/childrenAsContent.test.tsx
new file mode 100644
index 0000000000..213ed939dc
--- /dev/null
+++ b/packages/core/src/Layout/__tests__/childrenAsContent.test.tsx
@@ -0,0 +1,59 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file childrenAsContent.test.tsx
+ * @input Uses vitest, @testing-library/react
+ * @output Verifies Layout renders children as a shorthand for the content slot
+ * (so the natural `<Layout>…</Layout>` form never renders a blank shell), with
+ * an explicit `content` prop taking precedence.
+ */
+
+import {describe, it, expect} from 'vitest';
+import {render, screen} from '@testing-library/react';
+import {Layout} from '../Layout';
+import {LayoutContent} from '../LayoutContent';
+
+describe('Layout children-as-content', () => {
+ it('renders nested children in the content slot', () => {
+ render(
+ <Layout>
+ <LayoutContent>
+ <span data-testid="body">Body</span>
+ </LayoutContent>
+ </Layout>,
+ );
+ expect(screen.getByTestId('body')).toBeInTheDocument();
+ });
+
+ it('renders bare children (no LayoutContent wrapper) too', () => {
+ render(
+ <Layout>
+ <span data-testid="bare">Bare</span>
+ </Layout>,
+ );
+ expect(screen.getByTestId('bare')).toBeInTheDocument();
+ });
+
+ it('lets an explicit content prop win over children', () => {
+ render(
+ <Layout content={<span data-testid="slot">Slot</span>}>
+ <span data-testid="child">Child</span>
+ </Layout>,
+ );
+ expect(screen.getByTestId('slot')).toBeInTheDocument();
+ expect(screen.queryByTestId('child')).not.toBeInTheDocument();
+ });
+
+ it('still supports the canonical slot-only API', () => {
+ render(
+ <Layout
+ content={
+ <LayoutContent>
+ <span data-testid="canon">Canonical</span>
+ </LayoutContent>
+ }
+ />,
+ );
+ expect(screen.getByTestId('canon')).toBeInTheDocument();
+ });
+});