Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: HMR #2316

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

fix: HMR #2316

wants to merge 17 commits into from

Conversation

tannerlinsley
Copy link
Collaborator

No description provided.

Copy link

nx-cloud bot commented Sep 10, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit d6ccf25. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

Copy link

pkg-pr-new bot commented Sep 10, 2024

Open in Stackblitz

More templates

@tanstack/create-router

pnpm add https://pkg.pr.new/@tanstack/create-router@2316

@tanstack/eslint-plugin-router

pnpm add https://pkg.pr.new/@tanstack/eslint-plugin-router@2316

@tanstack/history

pnpm add https://pkg.pr.new/@tanstack/history@2316

@tanstack/react-cross-context

pnpm add https://pkg.pr.new/@tanstack/react-cross-context@2316

@tanstack/react-router

pnpm add https://pkg.pr.new/@tanstack/react-router@2316

@tanstack/react-router-with-query

pnpm add https://pkg.pr.new/@tanstack/react-router-with-query@2316

@tanstack/router-arktype-adapter

pnpm add https://pkg.pr.new/@tanstack/router-arktype-adapter@2316

@tanstack/router-cli

pnpm add https://pkg.pr.new/@tanstack/router-cli@2316

@tanstack/router-devtools

pnpm add https://pkg.pr.new/@tanstack/router-devtools@2316

@tanstack/router-generator

pnpm add https://pkg.pr.new/@tanstack/router-generator@2316

@tanstack/router-plugin

pnpm add https://pkg.pr.new/@tanstack/router-plugin@2316

@tanstack/router-valibot-adapter

pnpm add https://pkg.pr.new/@tanstack/router-valibot-adapter@2316

@tanstack/router-zod-adapter

pnpm add https://pkg.pr.new/@tanstack/router-zod-adapter@2316

@tanstack/router-vite-plugin

pnpm add https://pkg.pr.new/@tanstack/router-vite-plugin@2316

@tanstack/start

pnpm add https://pkg.pr.new/@tanstack/start@2316

@tanstack/start-vite-plugin

pnpm add https://pkg.pr.new/@tanstack/start-vite-plugin@2316

@tanstack/virtual-file-routes

pnpm add https://pkg.pr.new/@tanstack/virtual-file-routes@2316

commit: d6ccf25

@@ -142,7 +142,7 @@ export function compileCodeSplitReferenceRoute(opts: ParseAstOptions) {

programPath.pushContainer('body', [
template.statement(
`function DummyComponent() { return null }`,
`export function TSR_DummyComponent() { return null }`,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forces Fast Refresh to process the original route file even if we end up extracting the HMR passing conditions out of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking the route as an HMR boundary without handling HMR will lead to stale updates. Instead using the patch provided by @schiller-manuel in discord is good and both mark the module as an self accepting without fast refresh code and handle the update.

}
return null
},

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look ma'! No resolveId!

if (
fileIsInRoutesDirectory(id, userConfig.routesDirectory) ||
id.includes(splitPrefix)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't know if this was still necessary or not....

Comment on lines 327 to 329
componentId = splitNode.id?.name || componentId
programPath.pushContainer(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is great. Now the component is registered to fast refresh. Ideally people should not write anonymous component, but in that case giving it the name SplitComponent is better than having anonymous one

@@ -142,7 +142,7 @@ export function compileCodeSplitReferenceRoute(opts: ParseAstOptions) {

programPath.pushContainer('body', [
template.statement(
`function DummyComponent() { return null }`,
`export function TSR_DummyComponent() { return null }`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking the route as an HMR boundary without handling HMR will lead to stale updates. Instead using the patch provided by @schiller-manuel in discord is good and both mark the module as an self accepting without fast refresh code and handle the update.

@@ -20,7 +28,12 @@ export function getFullRouterManifest() {
if (process.env.NODE_ENV === 'development') {
rootRoute.assets.push({
tag: 'script',
children: `window.__vite_plugin_react_preamble_installed__ = true`,
attrs: { type: 'module' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArnaudBarre what's your take on this?

@Tsiangana
Copy link

Very good work!

@KiwiKilian
Copy link

We've been working quite successful on this branch, what's missing to merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants