Skip to content

fix: HMR - #2316

Closed
tannerlinsley wants to merge 17 commits into
mainfrom
fix-start-hmr
Closed

fix: HMR#2316
tannerlinsley wants to merge 17 commits into
mainfrom
fix-start-hmr

Conversation

@tannerlinsley

Copy link
Copy Markdown
Member

No description provided.

@nx-cloud

nx-cloud Bot commented Sep 10, 2024

Copy link
Copy Markdown
Contributor

☁️ 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.

@pkg-pr-new

pkg-pr-new Bot commented Sep 10, 2024

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown
Member 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
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
Member 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 thread packages/router-plugin/src/core/router-code-splitter-plugin.ts
Comment thread packages/router-plugin/src/core/router-code-splitter-plugin.ts
Comment thread packages/router-plugin/src/core/router-code-splitter-plugin.ts Outdated
Comment thread packages/router-generator/src/generator.ts Outdated
Comment on lines 327 to 329
componentId = splitNode.id?.name || componentId
programPath.pushContainer(

Copy link
Copy Markdown
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

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

Copy link
Copy Markdown
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.

rootRoute.assets.push({
tag: 'script',
children: `window.__vite_plugin_react_preamble_installed__ = true`,
attrs: { type: 'module' },

Copy link
Copy Markdown
Collaborator

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
Copy Markdown

Very good work!

@KiwiKilian

Copy link
Copy Markdown
Contributor

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

@SoloReverse

Copy link
Copy Markdown

Any timeline on when this might be merged?

@baptisteArno

Copy link
Copy Markdown

Is it possible to have a status update on this? Having to refresh the page for every change is a terrible DX 😢

@SeanCassiere

Copy link
Copy Markdown
Member

With exception to the work for mocking React Refresh in Start (as listed here), everything else in this PR has been pushed through in the merge of #3275 available in the https://github.com/TanStack/router/releases/tag/v1.98.2.

@SeanCassiere

SeanCassiere commented Feb 3, 2025

Copy link
Copy Markdown
Member

With exception to the work for mocking React Refresh in Start (as listed here), everything else in this PR has been pushed through in the merge of #3275 available in the v1.98.2 (release).

The remaining changes from this PR (changing the code snippet injected for Start's HMR) have been merged into main in #3313. As such, all the relevant changes from this PR have been merged in and as such I'll be closing this PR.

Thank you to everyone who's patiently waited till we worked on other fixes and changes for Start before focussing on merging this one in.

Edit: The changes to patch Start's HMR should be available from the https://github.com/TanStack/router/releases/tag/v1.99.3.

@SeanCassiere
SeanCassiere deleted the fix-start-hmr branch February 3, 2025 04:35
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.

8 participants