-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: HMR #2316
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
Closed
Closed
fix: HMR #2316
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
240a642
checkpoint
tannerlinsley 2ff6771
fix: simplify and fix HMR for router generator
tannerlinsley 7e4de9f
fix: revert example changes
tannerlinsley 227e48c
fix(start): force root to be HMR ready from #2286
SeanCassiere 35fe647
chore: oops, undo these changes to the example
SeanCassiere 17ca4a2
fix bugs
schiller-manuel 61f2dc1
removed unused imports
schiller-manuel 8d2740d
update snapshots
schiller-manuel 89ff13d
revert index
schiller-manuel 8e7ae0c
adapt bundlers
schiller-manuel 01a6c43
removed unused variables
schiller-manuel 9bca813
Merge branch 'main' into fix-start-hmr
SeanCassiere 5c19490
fix: whatever was broken from the branch update
SeanCassiere f85171d
fix: add the dummy component export back in
SeanCassiere ebe9476
fix: dummy component should return null
SeanCassiere 684eef6
Merge branch 'main' into fix-start-hmr
SeanCassiere d6ccf25
Merge branch 'main' into fix-start-hmr
SeanCassiere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| export const CONFIG_FILE_NAME = 'tsr.config.json' | ||
| export const splitPrefix = 'tsr-split' | ||
| export const splitToken = 'tsr-split' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ import { | |
| compileCodeSplitReferenceRoute, | ||
| compileCodeSplitVirtualRoute, | ||
| } from './code-splitter/compilers' | ||
| import { splitPrefix } from './constants' | ||
| import { splitToken } from './constants' | ||
|
|
||
| import type { Config } from './config' | ||
| import type { UnpluginContextMeta, UnpluginFactory } from 'unplugin' | ||
|
|
@@ -56,9 +56,6 @@ plugins: [ | |
| } | ||
| } | ||
|
|
||
| const PLUGIN_NAME = 'unplugin:router-code-splitter' | ||
| const JoinedSplitPrefix = splitPrefix + ':' | ||
|
|
||
| export const unpluginRouterCodeSplitterFactory: UnpluginFactory< | ||
| Partial<Config> | undefined | ||
| > = (options = {}, { framework }) => { | ||
|
|
@@ -110,18 +107,6 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory< | |
| return { | ||
| name: 'router-code-splitter-plugin', | ||
| enforce: 'pre', | ||
|
|
||
| resolveId(source) { | ||
| if (!userConfig.autoCodeSplitting) { | ||
| return null | ||
| } | ||
|
|
||
| if (source.startsWith(splitPrefix + ':')) { | ||
| return source.replace(splitPrefix + ':', '') | ||
| } | ||
| return null | ||
| }, | ||
|
|
||
| transform(code, id) { | ||
| if (!userConfig.autoCodeSplitting) { | ||
| return null | ||
|
|
@@ -131,7 +116,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory< | |
| url.searchParams.delete('v') | ||
| id = fileURLToPath(url).replace(/\\/g, '/') | ||
|
|
||
| if (id.includes(splitPrefix)) { | ||
| if (id.includes(splitToken)) { | ||
| return handleSplittingFile(code, id) | ||
| } else if ( | ||
| fileIsInRoutesDirectory(id, userConfig.routesDirectory) && | ||
|
|
@@ -158,15 +143,9 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory< | |
| return undefined | ||
| } | ||
|
|
||
| let id = transformId | ||
|
|
||
| if (id.startsWith(JoinedSplitPrefix)) { | ||
| id = id.replace(JoinedSplitPrefix, '') | ||
| } | ||
|
|
||
| if ( | ||
| fileIsInRoutesDirectory(id, userConfig.routesDirectory) || | ||
| id.includes(splitPrefix) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I honestly don't know if this was still necessary or not.... |
||
| fileIsInRoutesDirectory(transformId, userConfig.routesDirectory) || | ||
| transformId.includes(splitToken) | ||
| ) { | ||
| return true | ||
| } | ||
|
|
@@ -179,58 +158,19 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory< | |
|
|
||
| userConfig = getConfig(options, ROOT) | ||
| }, | ||
| // handleHotUpdate({ file, server, modules }) { | ||
| // return [] | ||
| // }, | ||
| }, | ||
|
|
||
| rspack(compiler) { | ||
| rspack() { | ||
| ROOT = process.cwd() | ||
|
|
||
| compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => { | ||
| self.normalModuleFactory.hooks.beforeResolve.tap( | ||
| PLUGIN_NAME, | ||
| (resolveData: { request: string }) => { | ||
| if (resolveData.request.includes(JoinedSplitPrefix)) { | ||
| resolveData.request = resolveData.request.replace( | ||
| JoinedSplitPrefix, | ||
| '', | ||
| ) | ||
| } | ||
| }, | ||
| ) | ||
| }) | ||
|
|
||
| userConfig = getConfig(options, ROOT) | ||
|
schiller-manuel marked this conversation as resolved.
|
||
| }, | ||
|
|
||
| webpack(compiler) { | ||
| webpack() { | ||
| ROOT = process.cwd() | ||
|
|
||
| compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => { | ||
| self.normalModuleFactory.hooks.beforeResolve.tap( | ||
| PLUGIN_NAME, | ||
| (resolveData: { request: string }) => { | ||
| if (resolveData.request.includes(JoinedSplitPrefix)) { | ||
| resolveData.request = resolveData.request.replace( | ||
| JoinedSplitPrefix, | ||
| '', | ||
| ) | ||
| } | ||
| }, | ||
| ) | ||
| }) | ||
|
|
||
| userConfig = getConfig(options, ROOT) | ||
|
|
||
| if ( | ||
| userConfig.autoCodeSplitting && | ||
| compiler.options.mode === 'production' | ||
| ) { | ||
| compiler.hooks.done.tap(PLUGIN_NAME, () => { | ||
| console.info('✅ ' + PLUGIN_NAME + ': code-splitting done!') | ||
| setTimeout(() => { | ||
| process.exit(0) | ||
| }) | ||
| }) | ||
| } | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
...outer-plugin/tests/code-splitter/snapshots/destructured-react-memo-imported-component.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| const $$splitLoaderImporter = () => import('tsr-split:destructured-react-memo-imported-component.tsx?tsr-split'); | ||
| const $$splitLoaderImporter = () => import('destructured-react-memo-imported-component.tsx?tsr-split'); | ||
| import { lazyFn } from '@tanstack/react-router'; | ||
| const $$splitComponentImporter = () => import('tsr-split:destructured-react-memo-imported-component.tsx?tsr-split'); | ||
| const $$splitComponentImporter = () => import('destructured-react-memo-imported-component.tsx?tsr-split'); | ||
| import { lazyRouteComponent } from '@tanstack/react-router'; | ||
| import { createFileRoute } from '@tanstack/react-router'; | ||
| export const Route = createFileRoute('/')({ | ||
| component: lazyRouteComponent($$splitComponentImporter, 'component'), | ||
| loader: lazyFn($$splitLoaderImporter, 'loader') | ||
| }); | ||
| }); | ||
| export function TSR_Dummy_Component() { | ||
| return null; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
packages/router-plugin/tests/code-splitter/snapshots/function-declaration.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| const $$splitComponentImporter = () => import('tsr-split:function-declaration.tsx?tsr-split'); | ||
| const $$splitComponentImporter = () => import('function-declaration.tsx?tsr-split'); | ||
| import { lazyRouteComponent } from '@tanstack/react-router'; | ||
| const $$splitLoaderImporter = () => import('tsr-split:function-declaration.tsx?tsr-split'); | ||
| const $$splitLoaderImporter = () => import('function-declaration.tsx?tsr-split'); | ||
| import { lazyFn } from '@tanstack/react-router'; | ||
| import { createFileRoute } from '@tanstack/react-router'; | ||
| export const Route = createFileRoute('/posts')({ | ||
| loader: lazyFn($$splitLoaderImporter, 'loader'), | ||
| component: lazyRouteComponent($$splitComponentImporter, 'component') | ||
| }); | ||
| }); | ||
| export function TSR_Dummy_Component() { | ||
| return null; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look ma'! No
resolveId!