Unverified Commit 3ee458e3 authored by Sukka's avatar Sukka Committed by GitHub

fix(#34030): ignore non-checkable jsx spread attribute (#34473)



## Bug

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

Fixes #34030.

The PR is still WIP as the test case hasn't been added, help or change is welcome.

cc @no-ya @ijjk 
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent fe312ed4
...@@ -28,16 +28,30 @@ module.exports = { ...@@ -28,16 +28,30 @@ module.exports = {
} }
const attributeNames = new Set() const attributeNames = new Set()
let hasNonCheckableSpreadAttribute = false
node.openingElement.attributes.forEach((attribute) => { node.openingElement.attributes.forEach((attribute) => {
// Early return if we already have a non-checkable spread attribute, for better performance
if (hasNonCheckableSpreadAttribute) return
if (attribute.type === 'JSXAttribute') { if (attribute.type === 'JSXAttribute') {
attributeNames.add(attribute.name.name) attributeNames.add(attribute.name.name)
} else if (attribute.type === 'JSXSpreadAttribute') { } else if (attribute.type === 'JSXSpreadAttribute') {
if (attribute.argument && attribute.argument.properties) {
attribute.argument.properties.forEach((property) => { attribute.argument.properties.forEach((property) => {
attributeNames.add(property.key.name) attributeNames.add(property.key.name)
}) })
} else {
// JSXSpreadAttribute without properties is not checkable
hasNonCheckableSpreadAttribute = true
}
} }
}) })
// https://github.com/vercel/next.js/issues/34030
// If there is a non-checkable spread attribute, we simply ignore them
if (hasNonCheckableSpreadAttribute) return
if ( if (
node.children.length > 0 || node.children.length > 0 ||
attributeNames.has('dangerouslySetInnerHTML') attributeNames.has('dangerouslySetInnerHTML')
......
...@@ -98,6 +98,17 @@ ruleTester.run('inline-script-id', rule, { ...@@ -98,6 +98,17 @@ ruleTester.run('inline-script-id', rule, {
) )
}`, }`,
}, },
{
code: `import Script from 'next/script';
const spread = { strategy: "lazyOnload" }
export default function TestPage() {
return (
<Script {...spread} id={"test-script"}>
{\`console.log('Hello world');\`}
</Script>
)
}`,
},
], ],
invalid: [ invalid: [
{ {
......
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