Unverified Commit 170dc0dc authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add check for ObjectExpression when iterating on <link> tags for font optimization (#26608)

Fixes #26547



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

## 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.

## Documentation / Examples

- [ ] Make sure the linting passes
parent 2f03bfa6
...@@ -89,8 +89,14 @@ export class FontStylesheetGatheringPlugin { ...@@ -89,8 +89,14 @@ export class FontStylesheetGatheringPlugin {
} }
// node.arguments[0] is the name of the tag and [1] are the props. // node.arguments[0] is the name of the tag and [1] are the props.
const propsNode = node.arguments[1] as namedTypes.ObjectExpression const arg1 = node.arguments[1]
const propsNode =
arg1.type === 'ObjectExpression'
? (arg1 as namedTypes.ObjectExpression)
: undefined
const props: { [key: string]: string } = {} const props: { [key: string]: string } = {}
if (propsNode) {
propsNode.properties.forEach((prop) => { propsNode.properties.forEach((prop) => {
if (prop.type !== 'Property') { if (prop.type !== 'Property') {
return return
...@@ -102,6 +108,8 @@ export class FontStylesheetGatheringPlugin { ...@@ -102,6 +108,8 @@ export class FontStylesheetGatheringPlugin {
props[prop.key.name] = prop.value.value as string props[prop.key.name] = prop.value.value as string
} }
}) })
}
if ( if (
!props.rel || !props.rel ||
props.rel !== 'stylesheet' || props.rel !== 'stylesheet' ||
......
import Document, { Html, Head, Main, NextScript } from 'next/document'
class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps }
}
render() {
const things = { className: 'test' }
return (
<Html>
<Head />
<link {...things} />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}
export default MyDocument
...@@ -328,4 +328,10 @@ describe('Font Optimization', () => { ...@@ -328,4 +328,10 @@ describe('Font Optimization', () => {
}) })
} }
) )
test('Spread operator regression on <link>', async () => {
const appDir = join(fixturesDir, 'spread-operator-regression')
const { code } = await nextBuild(appDir)
expect(code).toBe(0)
})
}) })
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