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
fix(#39993): avoid race condition for next/script onReady #40002
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
46b8959
test(#39993): add a failed case
SukkaW 2c6834c
fix(#39993): avoid race condition for next/script onReady
SukkaW edbb4ba
test(#39993): add case for inline script
SukkaW 2606ea8
Merge branch 'canary' into fix-39993
SukkaW f7669de
refactor: merge loadScripts handling
SukkaW c3cd6c1
test: split test cases
SukkaW 69b4bc6
Merge branch 'canary' into fix-39993
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
reactStrictMode: true, | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Script from 'next/script' | ||
import Link from 'next/link' | ||
|
||
if (typeof window !== 'undefined') { | ||
window.remoteScriptsOnReadyCalls ??= 0 | ||
window.inlineScriptsOnReadyCalls ??= 0 | ||
} | ||
|
||
const Page = () => { | ||
return ( | ||
<div className="container"> | ||
<Link href="/page9">Page 9</Link> | ||
<div id="text"></div> | ||
<Script | ||
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js" | ||
onReady={() => { | ||
window.remoteScriptsOnReadyCalls++ | ||
}} | ||
/> | ||
<Script | ||
id="i-am-an-inline-script-that-has-on-ready" | ||
dangerouslySetInnerHTML={{ __html: 'console.log("inline script!")' }} | ||
onReady={() => { | ||
window.inlineScriptsOnReadyCalls++ | ||
}} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
This file contains 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
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.
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.
Can we move this to the
else if (src) {
below so it's cleaner?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.
@shuding Sure!
BTW, do you have any suggestions about how to refactor the
beforeInteractive
inline script handling?Currently,
loadScript
is called directly in the render phase forworker
andbeforeInteractive
, making it react strict mode in-compatible. When I enablereactStrictMode
to validate my fix, other test cases begin to fail.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.
Updated in
f7669de
(#40002).