You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## I'm seeing a ``The Root component renders other content next to `{children}` `` error
4
+
5
+
With `ssr: false` (the default), the App is mounted into the parent element of `{children}` in your Root component, and React removes all other content from that element when mounting. This error means your Root component renders content that is silently removed this way in production builds.
6
+
7
+
Make `{children}` the only content of its parent element in the Root component (for example, wrap it in a dedicated `<div>`). See [How It Works](/learn/how-it-works#keep-children-alone-in-its-parent-element) for details.
8
+
3
9
## I'm seeing a ``<link rel=preload> must have a valid `as` value`` warning
4
10
5
11
This is a bug in React itself. Please wait for [the fix](https://github.com/facebook/react/pull/34760) to be released.
Copy file name to clipboardExpand all lines: packages/docs/src/pages/GettingStarted.mdx
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,7 @@ The Root component:
65
65
- is responsible for defining the shell HTML structure of your app
66
66
- is a server component
67
67
-**CANNOT** import client components; you could, but they are fully rendered into static HTML and never hydrated
68
+
- must render `{children}` as the only content of its parent element (unless SSR is enabled); see [How It Works](/learn/how-it-works#keep-children-alone-in-its-parent-element)
Copy file name to clipboardExpand all lines: packages/docs/src/pages/advanced/SSR.mdx
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,10 @@ This improves perceived performance, especially on:
30
30
31
31
The browser can start painting content as soon as the HTML arrives, while JavaScript loads in the background. Once loaded, React hydrates the existing HTML to make it interactive.
32
32
33
+
### No Root Layout Constraint
34
+
35
+
Without SSR, `{children}` must be the only content of its parent element in the Root component ([details](/learn/how-it-works#keep-children-alone-in-its-parent-element)). With SSR enabled, the whole document is hydrated instead of mounting the App into a container element, so this constraint does not apply.
Copy file name to clipboardExpand all lines: packages/docs/src/pages/learn/HowItWorks.mdx
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,6 +85,44 @@ The Root component is special in two ways:
85
85
86
86
The Root entrypoint is a FUNSTACK Static counterpart to the `index.html` file in traditional SPAs. It allows you to still leverage some of the benefits of server components for defining the HTML shell of your application.
87
87
88
+
### Keep `{children}` Alone in Its Parent Element
89
+
90
+
With `ssr: false` (the default), the App is mounted on the client into the parent element of `{children}`. React clears all existing content of that element when mounting, so any other content the Root component renders **in the same element** is removed from the page the moment the App mounts:
91
+
92
+
```tsx
93
+
// ❌ BAD: <header> and <footer> are removed when the App mounts
94
+
exportdefaultfunction Root({ children }: { children:React.ReactNode }) {
95
+
return (
96
+
<htmllang="en">
97
+
<body>
98
+
<header>My Site</header>
99
+
{children}
100
+
<footer>All rights reserved.</footer>
101
+
</body>
102
+
</html>
103
+
);
104
+
}
105
+
```
106
+
107
+
To avoid this, make `{children}` the only content of its parent element. Static content is safe anywhere else:
108
+
109
+
```tsx
110
+
// ✅ GOOD: {children} is the only content of its parent <div>
111
+
exportdefaultfunction Root({ children }: { children:React.ReactNode }) {
112
+
return (
113
+
<htmllang="en">
114
+
<body>
115
+
<header>My Site</header>
116
+
<div>{children}</div>
117
+
<footer>All rights reserved.</footer>
118
+
</body>
119
+
</html>
120
+
);
121
+
}
122
+
```
123
+
124
+
FUNSTACK Static reports a console error, both in development and in production builds, when it detects content that would be removed by the mount. If you want such content to survive, you can also move it into the App component, or enable [`ssr: true`](/advanced/ssr) — with SSR the whole document is hydrated and this constraint does not apply.
125
+
88
126
## Server-Side Rendering
89
127
90
128
By default, FUNSTACK Static only renders the Root shell to HTML. The App component is rendered client-side from its RSC payload. This behavior keeps the initial HTML small and fast to deliver.
Copy file name to clipboardExpand all lines: packages/static/skills/funstack-static-knowledge/SKILL.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,8 @@ export default defineConfig({
31
31
32
32
**Entrypoint.** Here, the `root` option points to the Root component of your application which is responsible for the HTML shell of your application. The `app` option points to the main App component which is the entrypoint for your application's UI.
33
33
34
+
**Root layout constraint.** Unless the `ssr` option is enabled, the Root component must render `{children}` as the only content of its parent element. The App is mounted into that parent element on the client, which removes any other content from it. Wrap `{children}` in a dedicated element (e.g. `<div>{children}</div>`) if the Root renders other content next to it.
35
+
34
36
**Server and Client Components.** The entrypoint components (Root and App) are **server components**. FUNSTACK Static follows React's conventions for Server and Client Components; the entrypoint is executed as a Server module. Modules marked with the `"use client"` directive are executed as Client modules. Server modules can import both Server and Client modules, while Client modules can only import other Client modules.
35
37
36
38
**Server Actions.** Note that Server Actions (`"use server"`) are **NOT** supported in FUNSTACK Static, as there is no server runtime deployed.
0 commit comments