Skip to content

Commit

Permalink
error recovery during turbopack hydration (#51882)
Browse files Browse the repository at this point in the history
### What?

Makes sure the next.js hydration code can run and that we can open the error overlay when there's an error in the entry page

Fixes WEB-1168
  • Loading branch information
ForsakenHarmony authored Jun 28, 2023
1 parent f1a4f7a commit f2dc6c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/next-swc/crates/next-core/js/src/entry/next-hydrate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { formatWithValidation } from 'next/dist/shared/lib/router/utils/format-u
import { initializeHMR } from '../dev/client'
import { subscribeToUpdate } from '@vercel/turbopack-ecmascript-runtime/dev/client/hmr-client'

import * as _app from '@vercel/turbopack-next/pages/_app'
import * as page from 'PAGE'

async function loadPageChunk(assetPrefix: string, chunkData: ChunkData) {
if (typeof chunkData === 'string') {
const fullPath = assetPrefix + chunkData
Expand Down Expand Up @@ -60,8 +57,11 @@ async function loadPageChunk(assetPrefix: string, chunkData: ChunkData) {
}

const pagePath = window.__NEXT_DATA__.page
window.__NEXT_P.push(['/_app', () => _app])
window.__NEXT_P.push([pagePath, () => page])
window.__NEXT_P.push([
'/_app',
() => require('@vercel/turbopack-next/pages/_app'),
])
window.__NEXT_P.push([pagePath, () => require('PAGE')])

console.debug('Hydrating the page')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as page from 'PAGE'

// inserted by rust code
declare const PAGE_PATH: string

// Adapted from https://github.com/vercel/next.js/blob/canary/packages/next/build/webpack/loaders/next-client-pages-loader.ts
;(window.__NEXT_P = window.__NEXT_P || []).push([
PAGE_PATH,
() => {
return page
return require('PAGE')
},
])
if (module.hot) {
Expand Down

0 comments on commit f2dc6c8

Please sign in to comment.