fix(dynamic): respect parent Suspense boundaries when no loading component is provided#93882
Open
MD-Mushfiqur123 wants to merge 2 commits into
Open
fix(dynamic): respect parent Suspense boundaries when no loading component is provided#93882MD-Mushfiqur123 wants to merge 2 commits into
MD-Mushfiqur123 wants to merge 2 commits into
Conversation
…onent is provided
Comment on lines
+51
to
+54
| // Only wrap in a Suspense boundary when a loading component is explicitly provided. | ||
| // When no loading component is given, use Fragment to allow parent Suspense | ||
| // boundaries to handle the loading state properly. | ||
| const hasSuspenseBoundary = !!opts.loading |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fixes
next/dynamic()creating an unnecessary inner<Suspense>boundary with an empty fallback when noloadingcomponent is provided, which prevents parent<Suspense>boundaries from working and causes layout flicker.Why?
When using
next/dynamic()without aloadingcomponent inside a parent<Suspense>:The current code forces an inner
<Suspense>boundary whenssr: false(line 52:const hasSuspenseBoundary = !opts.ssr || !!opts.loading). This inner boundary hasfallback={null}, which:<Suspense>fallbackcompletely uselessHow?
lazy-dynamic/loadable.tsx: Changed the condition so that a<Suspense>boundary is only created when aloadingcomponent is explicitly provided. Whenloadingisnull(default), use<Fragment>instead, allowing any parent<Suspense>to properly handle the loading state.loadable.shared-runtime.tsx: Added a null guard foropts.loadingto prevent aReact.createElement(null, ...)crash when no loading component is provided.Verification
loading=<Component>:<Suspense>is used with the given fallback (unchanged behavior)loading=null(default) withssr=true:<Fragment>is used, parent<Suspense>catches the lazy stateloading=null(default) withssr=false:<Fragment>is used,<BailoutToCSR>triggers the parent<Suspense>Fixes #73830