rsnext/tsec-exemptions.json
Adam Jones f563940f69
next/script: Correctly apply async and defer props (#52939)
### Summary

Fixes #52935

`next/script` has a `Script` component that supports an `async` prop.
However, when scripts are loaded with the `async` prop set to false, the
script is loaded as if async was set to true. This may cause scripts to
execute out of order. Repro:
https://github.com/domdomegg/next-async-script-reproduction

I think this is occurring because Next uses setAttribute to set the
async and defer attributes. However, this is not a valid way to set
these properties on a script. This is because . Demo:
https://jsfiddle.net/6ktpfae1/

This PR fixes this behaviour by using removeAttribute after calling
setAttribute (rather than using setAttribute "false"). This appears to
result in correct behaviour.

Given it appears this workaround was already applied in `next/head`,
I've harmonised the code between these two.

### Next steps

I think this PR is ready for review. I acknowledge there are no test
changes, but there are no existing tests for `next/script` at all and
creating them I think would be disproportionally difficult given issues
in #52943.

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Sam Ko <sam@vercel.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-04-15 15:01:50 -07:00

22 lines
972 B
JSON

{
"ban-element-innerhtml-assignments": [
"packages/next/src/client/head-manager.ts",
"packages/next/src/client/script.tsx",
"packages/next/src/client/dev/dev-build-watcher.ts",
"packages/next/src/client/app-bootstrap.ts"
],
"ban-element-setattribute": [
"packages/next/src/client/head-manager.ts",
"packages/next/src/client/script.tsx",
"packages/next/src/client/set-attributes-from-props.ts",
"packages/next/src/build/webpack/loaders/next-style-loader/runtime/injectStylesIntoLinkTag.ts",
"packages/next/src/build/webpack/loaders/next-style-loader/runtime/injectStylesIntoStyleTag.ts",
"packages/next/src/client/app-bootstrap.ts"
],
"ban-script-content-assignments": ["packages/next/src/client/script.tsx"],
"ban-script-src-assignments": [
"packages/next/src/client/script.tsx",
"packages/next/src/client/app-bootstrap.ts"
],
"ban-trustedtypes-createpolicy": ["packages/next/src/client/trusted-types.ts"]
}