Unverified Commit 5b21f091 authored by 残月's avatar 残月 Committed by GitHub

Fixes beforeInteractive inline scripts don't run (#37033)

BeforeInteractive inline script in v12.1.7-canary.8  don't run. Beacause the script has unknow src.

![image](https://user-images.githubusercontent.com/17813559/169257330-4419228a-6d10-4815-9451-d9a5dd7f011b.png)

Fixes https://github.com/vercel/next.js/issues/31275


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
parent 50833d00
...@@ -555,8 +555,13 @@ export class Head extends Component< ...@@ -555,8 +555,13 @@ export class Head extends Component<
!script.src && (script.dangerouslySetInnerHTML || script.children) !script.src && (script.dangerouslySetInnerHTML || script.children)
) )
.map((file: ScriptProps, index: number) => { .map((file: ScriptProps, index: number) => {
const { strategy, children, dangerouslySetInnerHTML, ...scriptProps } = const {
file strategy,
children,
dangerouslySetInnerHTML,
src,
...scriptProps
} = file
let html = '' let html = ''
if (dangerouslySetInnerHTML && dangerouslySetInnerHTML.__html) { if (dangerouslySetInnerHTML && dangerouslySetInnerHTML.__html) {
......
import Script from 'next/script'
const Page = () => {
return (
<div class="container">
<Script
id="beforeInteractiveInlineScript"
strategy="beforeInteractive"
>{`console.log('beforeInteractive inline script run')`}</Script>
<div>page7</div>
</div>
)
}
export default Page
...@@ -203,6 +203,24 @@ describe('Next.js Script - Primary Strategies', () => { ...@@ -203,6 +203,24 @@ describe('Next.js Script - Primary Strategies', () => {
).toBeGreaterThan(0) ).toBeGreaterThan(0)
}) })
it('priority beforeInteractive with inline script should execute', async () => {
let browser
try {
browser = await webdriver(appPort, '/page7')
await waitFor(1000)
const logs = await browser.log()
expect(
logs.some((log) =>
log.message.includes('beforeInteractive inline script run')
)
).toBe(true)
} finally {
if (browser) await browser.close()
}
})
it('Does not duplicate inline scripts', async () => { it('Does not duplicate inline scripts', async () => {
let browser let browser
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment