Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: #30962 This PR adds a new `onReady` prop to `next/script` to handle shortcomings of the current `onLoad` prop. Some third-party providers and widgets require initialization code to run after the script's `load` event and every time the component is mounted. The `onReady` should solve that use case. For more details, refer to the discussion in #30962. CC @janicklas-ralph ## Bug - [X] Related issues linked using `fixes #number` - [X] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
- Loading branch information
1 parent
85b00b2
commit a818606
Showing
6 changed files
with
143 additions
and
5 deletions.
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
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,24 @@ | ||
import Script from 'next/script' | ||
import Link from 'next/link' | ||
|
||
const url = | ||
'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js' | ||
|
||
const Page = () => { | ||
return ( | ||
<div class="container"> | ||
<Link href="/page9">Page 9</Link> | ||
<div id="text"></div> | ||
<Script | ||
src={url} | ||
id="script1" | ||
onReady={() => { | ||
// eslint-disable-next-line no-undef | ||
document.getElementById('text').textContent += _.repeat('a', 3) | ||
}} | ||
></Script> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Link from 'next/link' | ||
|
||
const Page = () => { | ||
return ( | ||
<> | ||
<Link href="/page8">Page 8</Link> | ||
</> | ||
) | ||
} | ||
|
||
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