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

Time slicing script loading in lazyOnLoad method 🛩️ #40190

Closed

Conversation

sanjaiyan-dev
Copy link
Contributor

@sanjaiyan-dev sanjaiyan-dev commented Sep 3, 2022

Time slicing script loading in lazyOnLoad method 🛩️

Thought-: We can replace requestIdleCallback with React.startTransition

Extremely sorry if I made any mistakes :(

@ijjk ijjk added the type: next label Sep 3, 2022
@sanjaiyan-dev sanjaiyan-dev marked this pull request as ready for review September 3, 2022 07:11
Comment on lines 123 to 129
window.addEventListener('load', () => {
requestIdleCallback(() => loadScript(props))
requestIdleCallback(() => {
nextjsStartTransition(() => {
loadScript(props)
})
})
})
Copy link
Contributor

@SukkaW SukkaW Sep 3, 2022

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.

Copy link
Contributor Author

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 add startTransition inside next/script, you may trigger many hidden race conditions.

Ohh ok & tks for explanation 💪🏽🤝

Copy link
Contributor Author

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.

#40191 can be implemented now ?

Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok :)

Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijjk ijjk closed this Sep 3, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants