Unverified Commit 927fc9e2 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

skip hot reload sync event for applying hmr updates (#52270)

### Issue

x-ref:
https://github.com/vercel/next.js/actions/runs/5469070005/jobs/9957658991?pr=52282#step:27:526
metadata tests are failing as flaky recently, then after digging into
it, noticed it as a hmr issue.

**Steps to repro with metadata test app**

The later (after the 1st one) visited page with client components
imports sometimes throw an full reload refresh warning
> Fast Refresh will perform a full reload when you edit a file that's
imported by modules
outside of the React rendering tree.

Turns out there's some unexpected hmr events when `"sync"` event is
triggered, and client tries to apply the updates but then failed. This
PR excludes the triggering by `"sync"` for RSC pages updates. `'sync'`
event with errors/warnings will still be handled and then `'built'`
event will be handled with hot reload updates

Possibly related to #40184
parent 3fb3bbbc
...@@ -335,9 +335,9 @@ function processMessage( ...@@ -335,9 +335,9 @@ function processMessage(
) )
const isHotUpdate = const isHotUpdate =
obj.action !== 'sync' || obj.action !== 'sync' &&
((!window.__NEXT_DATA__ || window.__NEXT_DATA__.page !== '/_error') && (!window.__NEXT_DATA__ || window.__NEXT_DATA__.page !== '/_error') &&
isUpdateAvailable()) isUpdateAvailable()
// Attempt to apply hot updates or reload. // Attempt to apply hot updates or reload.
if (isHotUpdate) { if (isHotUpdate) {
......
export function GET() {
return new Response('{ "name": "metadata-app", }', {
headers: {
'Content-Type': 'application/xml; charset=utf-8',
},
})
}
export function GET() {
return new Response('console.log("hello from preload")', {
headers: {
'Content-Type': 'application/javascript; charset=utf-8',
},
})
}
import { NextResponse } from 'next/server'
export function GET() { export function GET() {
return new NextResponse('hello api route') return new Response('hello api route')
} }
...@@ -5,7 +5,7 @@ import ReactDOM from 'react-dom' ...@@ -5,7 +5,7 @@ import ReactDOM from 'react-dom'
// NOTE: atm preload/prefetch/prefetchDNS are only supported in the SSR and client, not in RSC yet // NOTE: atm preload/prefetch/prefetchDNS are only supported in the SSR and client, not in RSC yet
export default function Client() { export default function Client() {
// @ts-ignore // @ts-ignore
ReactDOM.preload('/preload-url', { as: 'script' }) ReactDOM.preload('/api/preload', { as: 'script' })
// @ts-ignore // @ts-ignore
ReactDOM.preconnect('/preconnect-url', { crossOrigin: 'use-credentials' }) ReactDOM.preconnect('/preconnect-url', { crossOrigin: 'use-credentials' })
// @ts-ignore // @ts-ignore
......
...@@ -27,7 +27,7 @@ export const metadata: Metadata = { ...@@ -27,7 +27,7 @@ export const metadata: Metadata = {
authors: [{ name: 'huozhi' }, { name: 'tree', url: 'https://tree.com' }], authors: [{ name: 'huozhi' }, { name: 'tree', url: 'https://tree.com' }],
themeColor: { color: 'cyan', media: '(prefers-color-scheme: dark)' }, themeColor: { color: 'cyan', media: '(prefers-color-scheme: dark)' },
colorScheme: 'dark', colorScheme: 'dark',
manifest: 'https://www.google.com/manifest', manifest: '/api/manifest',
viewport: { viewport: {
width: 'device-width', width: 'device-width',
initialScale: 1, initialScale: 1,
......
...@@ -5,7 +5,7 @@ import ReactDOM from 'react-dom' ...@@ -5,7 +5,7 @@ import ReactDOM from 'react-dom'
// NOTE: atm preload/prefetch/prefetchDNS are only supported in the SSR and client, not in RSC yet // NOTE: atm preload/prefetch/prefetchDNS are only supported in the SSR and client, not in RSC yet
export default function Client() { export default function Client() {
// @ts-ignore // @ts-ignore
ReactDOM.preload('/preload-url', { as: 'script' }) ReactDOM.preload('/api/preload', { as: 'script' })
// @ts-ignore // @ts-ignore
ReactDOM.preconnect('/preconnect-url', { crossOrigin: 'use-credentials' }) ReactDOM.preconnect('/preconnect-url', { crossOrigin: 'use-credentials' })
// @ts-ignore // @ts-ignore
......
...@@ -25,7 +25,7 @@ export const metadata: Metadata = { ...@@ -25,7 +25,7 @@ export const metadata: Metadata = {
authors: [{ name: 'huozhi' }, { name: 'tree', url: 'https://tree.com' }], authors: [{ name: 'huozhi' }, { name: 'tree', url: 'https://tree.com' }],
themeColor: { color: 'cyan', media: '(prefers-color-scheme: dark)' }, themeColor: { color: 'cyan', media: '(prefers-color-scheme: dark)' },
colorScheme: 'dark', colorScheme: 'dark',
manifest: 'https://www.google.com/manifest', manifest: '/api/manifest',
viewport: { viewport: {
width: 'device-width', width: 'device-width',
initialScale: 1, initialScale: 1,
......
...@@ -7,9 +7,9 @@ export default function Page() { ...@@ -7,9 +7,9 @@ export default function Page() {
to / to /
</Link> </Link>
<br /> <br />
<Link href="/basic" id="to-basic"> {/* <Link href="/basic" id="to-basic">
to /basic to /basic
</Link> </Link> */}
</> </>
) )
} }
......
...@@ -217,10 +217,10 @@ createNextDescribe( ...@@ -217,10 +217,10 @@ createNextDescribe(
}) })
await matchMultiDom('link', 'rel', 'href', { await matchMultiDom('link', 'rel', 'href', {
manifest: 'https://www.google.com/manifest', manifest: '/api/manifest',
author: 'https://tree.com', author: 'https://tree.com',
preconnect: '/preconnect-url', preconnect: '/preconnect-url',
preload: '/preload-url', preload: '/api/preload',
'dns-prefetch': '/dns-prefetch-url', 'dns-prefetch': '/dns-prefetch-url',
}) })
...@@ -251,10 +251,10 @@ createNextDescribe( ...@@ -251,10 +251,10 @@ createNextDescribe(
}) })
await matchMultiDom('link', 'rel', 'href', { await matchMultiDom('link', 'rel', 'href', {
manifest: 'https://www.google.com/manifest', manifest: '/api/manifest',
author: 'https://tree.com', author: 'https://tree.com',
preconnect: '/preconnect-url', preconnect: '/preconnect-url',
preload: '/preload-url', preload: '/api/preload',
'dns-prefetch': '/dns-prefetch-url', 'dns-prefetch': '/dns-prefetch-url',
}) })
......
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