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
In my approach the React.Suspense boundary is within the Route element, because only the specific elements that are changing should wait for being loaded - so that the navigation bar doesn't disappear while loading the page.
Example code
Here's a shortened example from my App - the actual app has dynamic imports for ~30 components, splitting by view.
In this example ServerPage contains the navigation bar.
ServerOverview contains the cards that appear as the "main content" of the page.
The problem
In v6 this results in a behavior that upon clicking a Link, the router switches to an empty view until the Suspense resolves the required parts of the page, and then renders.
click
-> transition to empty page (~ milliseconds response time)
-> wait for dynamic imports to load (~0.2s-3s)
-> transition to the loaded page
In v7, I assume because of the startTransition change, upon navigate() nothing happens until the Suspense resolves - This leads to poor user experience, because there's a visible delay between user clicking and things happening
click
-> wait for dynamic imports to load (~0.2s-3s)
-> transition to the loaded page
How do I change this so that the router transitions to an empty view immediately to wait for the dynamic imports to load? I don't want to load the whole application in the background.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Alright, so I've implemented code splitting in my React application using React.lazy. The upgrade guide from v6 is just saying "It's bad React, fix it", when this approach was recommended a couple years ago https://legacy.reactjs.org/docs/code-splitting.html - So how do I fix it?
In my approach the React.Suspense boundary is within the Route element, because only the specific elements that are changing should wait for being loaded - so that the navigation bar doesn't disappear while loading the page.
Example code
Here's a shortened example from my App - the actual app has dynamic imports for ~30 components, splitting by view.
The problem
In v6 this results in a behavior that upon clicking a Link, the router switches to an empty view until the Suspense resolves the required parts of the page, and then renders.
In v7, I assume because of the startTransition change, upon navigate() nothing happens until the Suspense resolves - This leads to poor user experience, because there's a visible delay between user clicking and things happening
How do I change this so that the router transitions to an empty view immediately to wait for the dynamic imports to load? I don't want to load the whole application in the background.
Beta Was this translation helpful? Give feedback.
All reactions