Skip to content

Commit

Permalink
refactor(vercel#41164): polyfill-module should block hydration (verce…
Browse files Browse the repository at this point in the history
…l#41352)

The PR continues from vercel#41164.

`next/script` with `beforeInteractive` should not block the hydration,
**but the `polyfill-nomodule` *should* block the hydration** (and should
be loaded before other scripts), as `polyfill-nomodule` includes
multiple polyfills to even execute `main-app.[hash].js` properly on old
browsers (`Array.prototype.includes`, `String.prototype.startsWith`,
etc.).

Without `polyfill-nomodule` being loaded first, the entire
bootstrap/hydration process might not even work on old browsers. So it
should not be loaded through `__next_s`.

cc @shuding

Co-authored-by: Shu Ding <g@shud.in>
  • Loading branch information
2 people authored and Kikobeats committed Oct 24, 2022
1 parent d4b3c32 commit 1b9d69f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
11 changes: 2 additions & 9 deletions packages/next/server/app-render.tsx
Expand Up @@ -1479,17 +1479,10 @@ export async function renderToHTMLOrFlight(
return (
<script
key={polyfill.src}
src={polyfill.src}
integrity={polyfill.integrity}
noModule={true}
nonce={nonce}
dangerouslySetInnerHTML={{
__html: `(self.__next_s=self.__next_s||[]).push([${JSON.stringify(
polyfill.src
)},${
polyfill.integrity
? JSON.stringify({ integrity: polyfill.integrity })
: '{}'
}])`,
}}
/>
)
})}
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/app-dir/index.test.ts
Expand Up @@ -121,7 +121,9 @@ describe('app dir', () => {

it('should serve polyfills for browsers that do not support modules', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/index')
expect(html).toMatch(/\/_next\/static\/chunks\/polyfills(-.+)?\.js/)
expect(html).toMatch(
/<script src="\/_next\/static\/chunks\/polyfills(-\w+)?\.js" nomodule="">/
)
})

// TODO-APP: handle css modules fouc in dev
Expand Down

0 comments on commit 1b9d69f

Please sign in to comment.