Skip to content

Commit e271a63

Browse files
Merge branch 'canary' into reduce-swc-size-glibc-musl
2 parents 786e72c + d0e72fd commit e271a63

File tree

4 files changed

+68
-9
lines changed

4 files changed

+68
-9
lines changed

packages/next/pages/_document.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,21 +452,30 @@ export class Head extends Component<
452452
makeStylesheetInert(node: ReactNode): ReactNode[] {
453453
return React.Children.map(node, (c: any) => {
454454
if (
455-
c.type === 'link' &&
456-
c.props['href'] &&
455+
c?.type === 'link' &&
456+
c?.props?.href &&
457457
OPTIMIZED_FONT_PROVIDERS.some(({ url }) =>
458-
c.props['href'].startsWith(url)
458+
c?.props?.href?.startsWith(url)
459459
)
460460
) {
461-
const newProps = { ...(c.props || {}) }
462-
newProps['data-href'] = newProps['href']
463-
newProps['href'] = undefined
461+
const newProps = {
462+
...(c.props || {}),
463+
'data-href': c.props.href,
464+
href: undefined,
465+
}
466+
467+
return React.cloneElement(c, newProps)
468+
} else if (c?.props?.children) {
469+
const newProps = {
470+
...(c.props || {}),
471+
children: this.makeStylesheetInert(c.props.children),
472+
}
473+
464474
return React.cloneElement(c, newProps)
465-
} else if (c.props && c.props['children']) {
466-
c.props['children'] = this.makeStylesheetInert(c.props['children'])
467475
}
476+
468477
return c
469-
})
478+
}).filter(Boolean)
470479
}
471480

472481
render() {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Document, { Html, Head, Main, NextScript } from 'next/document'
2+
3+
class MyDocument extends Document {
4+
static async getInitialProps(ctx) {
5+
const initialProps = await Document.getInitialProps(ctx)
6+
return { ...initialProps }
7+
}
8+
9+
render() {
10+
return (
11+
<Html>
12+
<Head>
13+
<>
14+
{false && <script data-href="test"></script>}
15+
<link rel="preconnect" href="https://fonts.googleapis.com" />
16+
<link
17+
rel="preconnect"
18+
href="https://fonts.gstatic.com"
19+
crossOrigin
20+
/>
21+
<link
22+
href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap"
23+
rel="stylesheet"
24+
/>
25+
</>
26+
</Head>
27+
<body>
28+
<Main />
29+
<NextScript />
30+
</body>
31+
</Html>
32+
)
33+
}
34+
}
35+
36+
export default MyDocument
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function Home() {
2+
return (
3+
<h1>
4+
Falsey values contained in an element contained in Head should not result
5+
in an error!
6+
</h1>
7+
)
8+
}

test/integration/font-optimization/test/index.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,10 @@ describe('Font Optimization', () => {
328328
const { code } = await nextBuild(appDir)
329329
expect(code).toBe(0)
330330
})
331+
332+
test('makeStylesheetInert regression', async () => {
333+
const appDir = join(fixturesDir, 'make-stylesheet-inert-regression')
334+
const { code } = await nextBuild(appDir)
335+
expect(code).toBe(0)
336+
})
331337
})

0 commit comments

Comments
 (0)