Unverified Commit a92a3b6d authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Handle loading returning undefined (#40938)

Since React 18 returning `undefined` from components is allowed which renders to `undefined` in the RSC response so we need a separate prop to know if the loading boundary was provided.

Thanks to @finn-orsini who reported this problem.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent 406d69d4
...@@ -278,11 +278,14 @@ export function InnerLayoutRouter({ ...@@ -278,11 +278,14 @@ export function InnerLayoutRouter({
function LoadingBoundary({ function LoadingBoundary({
children, children,
loading, loading,
hasLoading,
}: { }: {
children: React.ReactNode children: React.ReactNode
loading?: React.ReactNode loading?: React.ReactNode
hasLoading: boolean
}): JSX.Element { }): JSX.Element {
if (loading) { if (hasLoading) {
// @ts-expect-error TODO-APP: React.Suspense fallback type is wrong
return <React.Suspense fallback={loading}>{children}</React.Suspense> return <React.Suspense fallback={loading}>{children}</React.Suspense>
} }
...@@ -450,6 +453,7 @@ export default function OuterLayoutRouter({ ...@@ -450,6 +453,7 @@ export default function OuterLayoutRouter({
childProp, childProp,
error, error,
loading, loading,
hasLoading,
template, template,
notFound, notFound,
rootLayoutIncluded, rootLayoutIncluded,
...@@ -460,6 +464,7 @@ export default function OuterLayoutRouter({ ...@@ -460,6 +464,7 @@ export default function OuterLayoutRouter({
error: ErrorComponent error: ErrorComponent
template: React.ReactNode template: React.ReactNode
loading: React.ReactNode | undefined loading: React.ReactNode | undefined
hasLoading: boolean
notFound: React.ReactNode | undefined notFound: React.ReactNode | undefined
rootLayoutIncluded: boolean rootLayoutIncluded: boolean
}) { }) {
...@@ -510,7 +515,7 @@ export default function OuterLayoutRouter({ ...@@ -510,7 +515,7 @@ export default function OuterLayoutRouter({
key={preservedSegment} key={preservedSegment}
value={ value={
<ErrorBoundary errorComponent={error}> <ErrorBoundary errorComponent={error}>
<LoadingBoundary loading={loading}> <LoadingBoundary hasLoading={hasLoading} loading={loading}>
<NotFoundBoundary notFound={notFound}> <NotFoundBoundary notFound={notFound}>
<RedirectBoundary> <RedirectBoundary>
<InnerLayoutRouter <InnerLayoutRouter
......
...@@ -942,6 +942,7 @@ export async function renderToHTMLOrFlight( ...@@ -942,6 +942,7 @@ export async function renderToHTMLOrFlight(
parallelRouterKey={parallelRouteKey} parallelRouterKey={parallelRouteKey}
segmentPath={createSegmentPath(currentSegmentPath)} segmentPath={createSegmentPath(currentSegmentPath)}
loading={Loading ? <Loading /> : undefined} loading={Loading ? <Loading /> : undefined}
hasLoading={Boolean(Loading)}
error={ErrorComponent} error={ErrorComponent}
template={ template={
<Template> <Template>
...@@ -982,6 +983,8 @@ export async function renderToHTMLOrFlight( ...@@ -982,6 +983,8 @@ export async function renderToHTMLOrFlight(
segmentPath={segmentPath} segmentPath={segmentPath}
error={ErrorComponent} error={ErrorComponent}
loading={Loading ? <Loading /> : undefined} loading={Loading ? <Loading /> : undefined}
// TODO-APP: Add test for loading returning `undefined`. This currently can't be tested as the `webdriver()` tab will wait for the full page to load before returning.
hasLoading={Boolean(Loading)}
template={ template={
<Template> <Template>
<RenderFromTemplateContext /> <RenderFromTemplateContext />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment