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
Time slicing script loading in lazyOnLoad
method 🛩️
#40190
Time slicing script loading in lazyOnLoad
method 🛩️
#40190
Conversation
window.addEventListener('load', () => { | ||
requestIdleCallback(() => loadScript(props)) | ||
requestIdleCallback(() => { | ||
nextjsStartTransition(() => { | ||
loadScript(props) | ||
}) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per React documents:
React.startTransition
lets you mark updates inside the provided callback as transitions.
However, calling loadScript
will not trigger an "update" (loadScript
will not cause a state update or trigger a re-render, as it manipulates DOM directly, bypassing React completely).
Besides, currently next/script
component is not concurrent rendering safe at all (see #40025), and calling concurrent API will cause the component (and its children) to opt-in concurrent rendering. If you add startTransition
inside next/script
, you may trigger many hidden race conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per React documents:
React.startTransition
lets you mark updates inside the provided callback as transitions.However, calling
loadScript
will not trigger an "update" (loadScript
will not cause a state update or triggers a re-render, as it manipulates DOM directly, bypassing React completely).Besides, currently
next/script
component is not concurrent rendering safe at all (see #40025), and calling concurrent API will cause the component (and its children) to opt-in concurrent rendering. If you addstartTransition
insidenext/script
, you may trigger many hidden race conditions.
Ohh ok & tks for explanation 💪🏽🤝
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per React documents:
React.startTransition
lets you mark updates inside the provided callback as transitions.However, calling
loadScript
will not trigger an "update" (loadScript
will not cause a state update or trigger a re-render, as it manipulates DOM directly, bypassing React completely).Besides, currently
next/script
component is not concurrent rendering safe at all (see #40025), and calling concurrent API will cause the component (and its children) to opt-in concurrent rendering. If you addstartTransition
insidenext/script
, you may trigger many hidden race conditions.
#40191 can be implemented now ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still no.
Per React documents:
React.startTransition
lets you mark updates inside the provided callback as transitions.However, calling
loadScript
will not trigger an "update" (loadScript
will not cause a state update or trigger a re-render, as it manipulates DOM directly, bypassing React completely).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closing per above discussion https://github.com/vercel/next.js/pull/40190/files#r962118916
Time slicing script loading in
lazyOnLoad
method 🛩️Extremely sorry if I made any mistakes :(