Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
476bb09b
Unverified
Commit
476bb09b
authored
Dec 07, 2022
by
Shu Ding
Committed by
GitHub
Dec 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix HMR issue after patching the client module (#43819)
Co-authored-by:
Tim Neutkens
<
tim@timneutkens.nl
>
parent
56ea3061
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
9 deletions
+48
-9
app-index.tsx
packages/next/client/app-index.tsx
+4
-1
app-render.tsx
packages/next/server/app-render.tsx
+25
-1
index.test.ts
test/e2e/app-dir/index.test.ts
+19
-7
No files found.
packages/next/client/app-index.tsx
View file @
476bb09b
...
@@ -29,7 +29,10 @@ __webpack_require__.u = (chunkId: any) => {
...
@@ -29,7 +29,10 @@ __webpack_require__.u = (chunkId: any) => {
// Ignore the module ID transform in client.
// Ignore the module ID transform in client.
// eslint-disable-next-line no-undef
// eslint-disable-next-line no-undef
// @ts-expect-error TODO: fix type
// @ts-expect-error TODO: fix type
self
.
__next_require__
=
__webpack_require__
self
.
__next_require__
=
(
id
:
string
)
=>
{
const
modId
=
id
.
replace
(
/
\?
.+$/
,
''
)
return
__webpack_require__
(
modId
)
}
// eslint-disable-next-line no-undef
// eslint-disable-next-line no-undef
;(
self
as
any
).
__next_chunk_load__
=
(
chunk
:
string
)
=>
{
;(
self
as
any
).
__next_chunk_load__
=
(
chunk
:
string
)
=>
{
...
...
packages/next/server/app-render.tsx
View file @
476bb09b
...
@@ -1598,11 +1598,35 @@ export async function renderToHTMLOrFlight(
...
@@ -1598,11 +1598,35 @@ export async function renderToHTMLOrFlight(
).
slice
(
1
),
).
slice
(
1
),
]
]
const
serverComponentManifestWithHMR
=
dev
?
new
Proxy
(
serverComponentManifest
,
{
get
:
(
target
,
prop
)
=>
{
if
(
typeof
prop
===
'string'
&&
!
prop
.
startsWith
(
'_'
)
&&
target
[
prop
]
)
{
// Attach TS (timestamp) query param to IDs to get rid of flight client's module cache on HMR.
const
namedExports
:
any
=
{}
const
ts
=
Date
.
now
()
for
(
let
key
in
target
[
prop
])
{
namedExports
[
key
]
=
{
...
target
[
prop
][
key
],
id
:
`
${
target
[
prop
][
key
].
id
}
?ts=
${
ts
}
`
,
}
}
return
namedExports
}
return
target
[
prop
]
},
})
:
serverComponentManifest
// For app dir, use the bundled version of Fizz renderer (renderToReadableStream)
// For app dir, use the bundled version of Fizz renderer (renderToReadableStream)
// which contains the subset React.
// which contains the subset React.
const
readable
=
ComponentMod
.
renderToReadableStream
(
const
readable
=
ComponentMod
.
renderToReadableStream
(
flightData
,
flightData
,
serverComponentManifest
,
serverComponentManifest
WithHMR
,
{
{
context
:
serverContexts
,
context
:
serverContexts
,
onError
:
flightDataRendererErrorHandler
,
onError
:
flightDataRendererErrorHandler
,
...
...
test/e2e/app-dir/index.test.ts
View file @
476bb09b
...
@@ -441,7 +441,7 @@ describe('app dir', () => {
...
@@ -441,7 +441,7 @@ describe('app dir', () => {
}
}
})
})
it
.
skip
(
'should HMR correctly when changing the component type'
,
async
()
=>
{
it
(
'should HMR correctly when changing the component type'
,
async
()
=>
{
const
filePath
=
'app/dashboard/page/page.jsx'
const
filePath
=
'app/dashboard/page/page.jsx'
const
origContent
=
await
next
.
readFile
(
filePath
)
const
origContent
=
await
next
.
readFile
(
filePath
)
...
@@ -466,13 +466,12 @@ describe('app dir', () => {
...
@@ -466,13 +466,12 @@ describe('app dir', () => {
)
)
// Change to client component
// Change to client component
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1000
))
await
next
.
patchFile
(
await
next
.
patchFile
(
filePath
,
filePath
,
origContent
origContent
.
replace
(
"// 'use client'"
,
"'use client'"
)
.
replace
(
"// 'use client'"
,
"'use client'"
)
.
replace
(
.
replace
(
'hello dashboard/page
in server component
!'
,
'hello dashboard/page!'
,
'hello dashboard/page in client component!'
'hello dashboard/page in client component!'
)
)
)
)
...
@@ -482,18 +481,31 @@ describe('app dir', () => {
...
@@ -482,18 +481,31 @@ describe('app dir', () => {
)
)
// Change back to server component
// Change back to server component
await
next
.
patchFile
(
filePath
,
origContent
.
replace
(
'hello dashboard/page!'
,
'hello dashboard/page in server component2!'
)
)
await
check
(
()
=>
browser
.
elementByCss
(
'p'
).
text
(),
/in server component2/
)
// Change to client component again
await
next
.
patchFile
(
await
next
.
patchFile
(
filePath
,
filePath
,
origContent
origContent
.
replace
(
"
'use client'"
,
"//
'use client'"
)
.
replace
(
"
// 'use client'"
,
"
'use client'"
)
.
replace
(
.
replace
(
'hello dashboard/page
in client component
!'
,
'hello dashboard/page!'
,
'hello dashboard/page in
server component
!'
'hello dashboard/page in
client component2
!'
)
)
)
)
await
check
(
await
check
(
()
=>
browser
.
elementByCss
(
'p'
).
text
(),
()
=>
browser
.
elementByCss
(
'p'
).
text
(),
/in
server component
/
/in
client component2
/
)
)
}
finally
{
}
finally
{
await
next
.
patchFile
(
filePath
,
origContent
)
await
next
.
patchFile
(
filePath
,
origContent
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment