diff --git a/packages/eslint-plugin-next/lib/rules/inline-script-id.js b/packages/eslint-plugin-next/lib/rules/inline-script-id.js index 20322f913c22d47..2254bd8d4715422 100644 --- a/packages/eslint-plugin-next/lib/rules/inline-script-id.js +++ b/packages/eslint-plugin-next/lib/rules/inline-script-id.js @@ -28,16 +28,30 @@ module.exports = { } const attributeNames = new Set() + + let hasNonCheckableSpreadAttribute = false 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') { attributeNames.add(attribute.name.name) } else if (attribute.type === 'JSXSpreadAttribute') { - attribute.argument.properties.forEach((property) => { - attributeNames.add(property.key.name) - }) + if (attribute.argument && attribute.argument.properties) { + attribute.argument.properties.forEach((property) => { + 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 ( node.children.length > 0 || attributeNames.has('dangerouslySetInnerHTML') diff --git a/test/unit/eslint-plugin-next/inline-script-id.test.ts b/test/unit/eslint-plugin-next/inline-script-id.test.ts index d584af36402ad75..2c563481c27a08d 100644 --- a/test/unit/eslint-plugin-next/inline-script-id.test.ts +++ b/test/unit/eslint-plugin-next/inline-script-id.test.ts @@ -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 ( + + ) + }`, + }, ], invalid: [ {