Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle loading returning undefined #40938

Merged
merged 2 commits into from Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/next/client/components/layout-router.client.tsx
Expand Up @@ -278,11 +278,14 @@ export function InnerLayoutRouter({
function LoadingBoundary({
children,
loading,
hasLoading,
}: {
children: React.ReactNode
loading?: React.ReactNode
hasLoading: boolean
}): 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>
}

Expand Down Expand Up @@ -450,6 +453,7 @@ export default function OuterLayoutRouter({
childProp,
error,
loading,
hasLoading,
template,
notFound,
rootLayoutIncluded,
Expand All @@ -460,6 +464,7 @@ export default function OuterLayoutRouter({
error: ErrorComponent
template: React.ReactNode
loading: React.ReactNode | undefined
hasLoading: boolean
notFound: React.ReactNode | undefined
rootLayoutIncluded: boolean
}) {
Expand Down Expand Up @@ -510,7 +515,7 @@ export default function OuterLayoutRouter({
key={preservedSegment}
value={
<ErrorBoundary errorComponent={error}>
<LoadingBoundary loading={loading}>
<LoadingBoundary hasLoading={hasLoading} loading={loading}>
<NotFoundBoundary notFound={notFound}>
<RedirectBoundary>
<InnerLayoutRouter
Expand Down
3 changes: 3 additions & 0 deletions packages/next/server/app-render.tsx
Expand Up @@ -942,6 +942,7 @@ export async function renderToHTMLOrFlight(
parallelRouterKey={parallelRouteKey}
segmentPath={createSegmentPath(currentSegmentPath)}
loading={Loading ? <Loading /> : undefined}
hasLoading={Boolean(Loading)}
error={ErrorComponent}
template={
<Template>
Expand Down Expand Up @@ -982,6 +983,8 @@ export async function renderToHTMLOrFlight(
segmentPath={segmentPath}
error={ErrorComponent}
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>
<RenderFromTemplateContext />
Expand Down