diff --git a/.gitignore b/.gitignore index 460a9f4dcfc..b260676a76a 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,8 @@ coverage packages/router-generator/tests/**/*.gen.ts packages/router-generator/tests/**/*.gen.js e2e/**/port*.txt +test-results/ +**/test-results/ # misc .DS_Store @@ -79,3 +81,6 @@ vite.config.ts.timestamp_* **/llms **/.tanstack + +# Claude Code settings +.claude/ diff --git a/packages/router-plugin/src/core/code-splitter/compilers.ts b/packages/router-plugin/src/core/code-splitter/compilers.ts index 43b8c8db4f6..cab7ac309f9 100644 --- a/packages/router-plugin/src/core/code-splitter/compilers.ts +++ b/packages/router-plugin/src/core/code-splitter/compilers.ts @@ -81,16 +81,34 @@ function addSplitSearchParamToFilename( ) { const [bareFilename] = filename.split('?') + // Don't modify absolute paths - they're used internally by bundlers + // Only ensure relative import specifier for relative paths + const relativeFilename = + bareFilename!.startsWith('/') || // Unix absolute path + /^[a-zA-Z]:/.test(bareFilename!) || // Windows absolute path (C:\ or C:/) + bareFilename!.startsWith('./') || + bareFilename!.startsWith('../') + ? bareFilename! + : `./${bareFilename!}` + const params = new URLSearchParams() params.append(tsrSplit, createIdentifier(grouping)) - const result = `${bareFilename}?${params.toString()}` + const result = `${relativeFilename}?${params.toString()}` return result } function removeSplitSearchParamFromFilename(filename: string) { const [bareFilename] = filename.split('?') - return bareFilename! + + // Don't modify absolute paths - they're used internally by bundlers + // Only ensure relative import specifier for relative paths + return bareFilename!.startsWith('/') || // Unix absolute path + /^[a-zA-Z]:/.test(bareFilename!) || // Windows absolute path (C:\ or C:/) + bareFilename!.startsWith('./') || + bareFilename!.startsWith('../') + ? bareFilename! + : `./${bareFilename!}` } const splittableCreateRouteFns = ['createFileRoute'] @@ -103,6 +121,31 @@ const allCreateRouteFns = [ ...unsplittableCreateRouteFns, ] +/** + * Helper to check if a VariableDeclarator is at module level. + * Handles both: + * - `const x = ...` (Program > VariableDeclaration > VariableDeclarator) + * - `export const x = ...` (Program > ExportNamedDeclaration > VariableDeclaration > VariableDeclarator) + */ +function isTopLevelVarDecl( + declaratorPath: babel.NodePath, +): boolean { + const varDecl = declaratorPath.parentPath + if (!varDecl.isVariableDeclaration()) return false + + const parent = varDecl.parentPath + + // Direct: Program > VariableDeclaration + if (parent.isProgram()) return true + + // Exported: Program > ExportNamedDeclaration > VariableDeclaration + if (parent.isExportNamedDeclaration() && parent.parentPath.isProgram()) { + return true + } + + return false +} + export function compileCodeSplitReferenceRoute( opts: ParseAstOptions & { codeSplitGroupings: CodeSplitGroupings @@ -111,6 +154,7 @@ export function compileCodeSplitReferenceRoute( filename: string id: string addHmr?: boolean + sharedExports?: Set }, ): GeneratorResult | null { const ast = parseAst(opts) @@ -118,6 +162,7 @@ export function compileCodeSplitReferenceRoute( const refIdents = findReferencedIdentifiers(ast) const knownExportedIdents = new Set() + const sharedModuleLevelIdents = new Set() function findIndexForSplitNode(str: string) { return opts.codeSplitGroupings.findIndex((group) => @@ -165,6 +210,52 @@ export function compileCodeSplitReferenceRoute( return programPath.scope.hasBinding(name) } + // Helper to collect all identifiers referenced by a node + const collectReferencedIdentifiers = ( + propPath: babel.NodePath, + ): Set => { + const identifiers = new Set() + const valuePath = propPath.get('value') + + // If the value is an identifier, we need to follow it to its definition + const pathsToAnalyze: Array = [] + + if (valuePath.isIdentifier()) { + const binding = valuePath.scope.getBinding( + valuePath.node.name, + ) + if (binding) { + pathsToAnalyze.push(binding.path) + } + } else { + pathsToAnalyze.push(valuePath) + } + + // Traverse each path to find all referenced identifiers + pathsToAnalyze.forEach((analyzePath) => { + analyzePath.traverse({ + Identifier(idPath) { + // Only collect identifiers that are references (not declarations) + if (!idPath.isReferencedIdentifier()) return + + const name = idPath.node.name + // Use idPath.scope to properly handle shadowing + const binding = idPath.scope.getBinding(name) + + // Only include identifiers that are defined at module level + if (binding && binding.path.isVariableDeclarator()) { + // Use the helper to check for top-level (handles both direct and exported) + if (isTopLevelVarDecl(binding.path)) { + identifiers.add(name) + } + } + }, + }) + }) + + return identifiers + } + if (t.isObjectExpression(routeOptions)) { if (opts.deleteNodes && opts.deleteNodes.size > 0) { routeOptions.properties = routeOptions.properties.filter( @@ -191,6 +282,43 @@ export function compileCodeSplitReferenceRoute( // exit traversal so this route is not split return programPath.stop() } + + // First pass: collect identifiers used by split vs non-split properties + const splitPropertyIdents = new Set() + const nonSplitPropertyIdents = new Set() + + // We need to analyze the route options object to find shared identifiers + // Since routeOptions might be a resolved node, we traverse from programPath + // to find all ObjectProperty paths and analyze them + programPath.traverse({ + ObjectProperty(propPath) { + // Check if this property belongs to the route options by checking its parent + if (!t.isObjectExpression(propPath.parent)) return + if (propPath.parent !== routeOptions) return + if (!t.isIdentifier(propPath.node.key)) return + + const key = propPath.node.key.name + const willBeSplit = + findIndexForSplitNode(key) !== -1 && + SPLIT_NODES_CONFIG.has(key as any) + + const idents = collectReferencedIdentifiers(propPath) + + if (willBeSplit) { + idents.forEach((id) => splitPropertyIdents.add(id)) + } else { + idents.forEach((id) => nonSplitPropertyIdents.add(id)) + } + }, + }) + + // Find shared identifiers that need to be exported + splitPropertyIdents.forEach((ident) => { + if (nonSplitPropertyIdents.has(ident)) { + sharedModuleLevelIdents.add(ident) + } + }) + routeOptions.properties.forEach((prop) => { if (t.isObjectProperty(prop)) { if (t.isIdentifier(prop.key)) { @@ -423,6 +551,116 @@ export function compileCodeSplitReferenceRoute( }, }) } + + /** + * Export shared module-level variables that are used by both + * split properties (e.g., component) and non-split properties (e.g., loader) + * This prevents double initialization when the split file is loaded + */ + if (sharedModuleLevelIdents.size > 0) { + modified = true + + // Track which variable declarations we've already processed to avoid duplicate processing + const processedVarDecls = new Set< + babel.NodePath + >() + + sharedModuleLevelIdents.forEach((identName) => { + const binding = programPath.scope.getBinding(identName) + if (!binding) return + + const bindingPath = binding.path + + // Check if it's a variable declaration at the top level + // (handles both `const x = ...` and `export const x = ...`) + if ( + bindingPath.isVariableDeclarator() && + isTopLevelVarDecl(bindingPath) + ) { + const varDecl = + bindingPath.parentPath as babel.NodePath + + // Only export const/let declarations (not imports or functions) + if ( + varDecl.node.kind === 'const' || + varDecl.node.kind === 'let' + ) { + // Skip if we've already processed this declaration + if (processedVarDecls.has(varDecl)) { + return + } + processedVarDecls.add(varDecl) + + // If already exported, just track it - don't re-export + if (varDecl.parentPath.isExportNamedDeclaration()) { + knownExportedIdents.add(identName) + opts.sharedExports?.add(identName) + return + } + + // Check if this declaration has multiple declarators + const declarators = varDecl.node.declarations + if (declarators.length > 1) { + // Split declarators: shared ones get exported, others stay local + const sharedDeclarators: Array = [] + const localDeclarators: Array = [] + + declarators.forEach((declarator) => { + if ( + t.isIdentifier(declarator.id) && + sharedModuleLevelIdents.has(declarator.id.name) + ) { + sharedDeclarators.push(declarator) + knownExportedIdents.add(declarator.id.name) + opts.sharedExports?.add(declarator.id.name) + } else { + localDeclarators.push(declarator) + } + }) + + // Replace with split declarations + if ( + sharedDeclarators.length > 0 && + localDeclarators.length > 0 + ) { + // Both shared and local declarators + const localVarDecl = t.variableDeclaration( + varDecl.node.kind, + localDeclarators, + ) + const sharedVarDecl = t.variableDeclaration( + varDecl.node.kind, + sharedDeclarators, + ) + const exportDecl = t.exportNamedDeclaration( + sharedVarDecl, + [], + ) + + varDecl.replaceWithMultiple([localVarDecl, exportDecl]) + } else if (sharedDeclarators.length > 0) { + // All declarators are shared + const sharedVarDecl = t.variableDeclaration( + varDecl.node.kind, + sharedDeclarators, + ) + const exportDecl = t.exportNamedDeclaration( + sharedVarDecl, + [], + ) + varDecl.replaceWith(exportDecl) + } + } else { + // Single declarator - export the whole thing + const exportDecl = t.exportNamedDeclaration(varDecl.node, []) + varDecl.replaceWith(exportDecl) + knownExportedIdents.add(identName) + opts.sharedExports?.add(identName) + } + } + } + }) + } }, }, }) @@ -463,6 +701,7 @@ export function compileCodeSplitVirtualRoute( opts: ParseAstOptions & { splitTargets: Array filename: string + sharedExports?: Set }, ): GeneratorResult { const ast = parseAst(opts) @@ -762,6 +1001,121 @@ export function compileCodeSplitVirtualRoute( } }, }) + + // Import shared module-level variables that were exported in the reference file + // Only process variables confirmed to be in the sharedExports set + if (opts.sharedExports && opts.sharedExports.size > 0) { + const candidateVariables: Array = [] + const reassignedVariables = new Set() + + // First pass: find candidate variables to import + programPath.traverse({ + VariableDeclaration(varDeclPath) { + // Only process top-level const/let declarations + if (!varDeclPath.parentPath.isProgram()) return + if ( + varDeclPath.node.kind !== 'const' && + varDeclPath.node.kind !== 'let' + ) + return + + varDeclPath.node.declarations.forEach((declarator) => { + if (!t.isIdentifier(declarator.id)) return + + const varName = declarator.id.name + + // Only import if this variable is in the confirmed shared exports set + if (opts.sharedExports!.has(varName)) { + candidateVariables.push(varName) + } + }) + }, + }) + + // Second pass: detect reassignments/updates to candidate variables + // Reassigned imports produce invalid ESM, so we must skip them + programPath.traverse({ + AssignmentExpression(path) { + if (t.isIdentifier(path.node.left)) { + const name = path.node.left.name + if (candidateVariables.includes(name)) { + reassignedVariables.add(name) + } + } + }, + UpdateExpression(path) { + if (t.isIdentifier(path.node.argument)) { + const name = path.node.argument.name + if (candidateVariables.includes(name)) { + reassignedVariables.add(name) + } + } + }, + }) + + // Warn about reassigned variables and filter them out + if (reassignedVariables.size > 0) { + const varList = Array.from(reassignedVariables).join(', ') + console.warn( + `[tanstack-router] Cannot import shared variable(s) [${varList}] in "${opts.filename}" because they are reassigned in the split file. ` + + `Imported bindings are read-only in ESM. Consider using 'const' with an object and mutating properties instead of reassigning the binding.`, + ) + } + + // Only import variables that are not reassigned + const variablesToImport = candidateVariables.filter( + (name) => !reassignedVariables.has(name), + ) + + // Remove shared variable declarations and add imports + if (variablesToImport.length > 0) { + programPath.traverse({ + VariableDeclaration(varDeclPath) { + if (!varDeclPath.parentPath.isProgram()) return + + const declaratorsToKeep = varDeclPath.node.declarations.filter( + (declarator) => { + if (!t.isIdentifier(declarator.id)) return true + return !variablesToImport.includes(declarator.id.name) + }, + ) + + if (declaratorsToKeep.length === 0) { + varDeclPath.remove() + } else if ( + declaratorsToKeep.length < + varDeclPath.node.declarations.length + ) { + varDeclPath.node.declarations = declaratorsToKeep + } + }, + }) + + // Add import statement for shared variables + const importDecl = t.importDeclaration( + variablesToImport.map((name) => + t.importSpecifier(t.identifier(name), t.identifier(name)), + ), + t.stringLiteral( + removeSplitSearchParamFromFilename(opts.filename), + ), + ) + programPath.unshiftContainer('body', importDecl) + + // Track imported identifiers for dead code elimination + const importPath = programPath.get('body')[0] as babel.NodePath + importPath.traverse({ + Identifier(identPath) { + if ( + identPath.parentPath.isImportSpecifier() && + identPath.key === 'local' + ) { + refIdents.add(identPath) + } + }, + }) + } + } }, }, }) diff --git a/packages/router-plugin/src/core/router-code-splitter-plugin.ts b/packages/router-plugin/src/core/router-code-splitter-plugin.ts index 2fe2af28b37..28b9e80460e 100644 --- a/packages/router-plugin/src/core/router-code-splitter-plugin.ts +++ b/packages/router-plugin/src/core/router-code-splitter-plugin.ts @@ -66,6 +66,10 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory< let ROOT: string = process.cwd() let userConfig: Config + // Cache of shared module-level variables that were exported in reference files + // Key: base filename (without query params), Value: Set of exported identifier names + const sharedExportsCache = new Map>() + function initUserConfig() { if (typeof options === 'function') { userConfig = options() @@ -125,6 +129,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory< const splitGroupings: CodeSplitGroupings = fromCode.groupings || pluginSplitBehavior || getGlobalCodeSplitGroupings() + const sharedExports = new Set() const compiledReferenceRoute = compileCodeSplitReferenceRoute({ code, codeSplitGroupings: splitGroupings, @@ -136,8 +141,15 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory< : undefined, addHmr: (userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction, + sharedExports, }) + // Cache shared exports for virtual route compilation + if (sharedExports.size > 0) { + const baseFilename = id.split('?')[0]! + sharedExportsCache.set(baseFilename, sharedExports) + } + if (compiledReferenceRoute === null) { if (debug) { console.info( @@ -176,10 +188,15 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory< splitRouteIdentNodes.includes(p as any), ) as Array + // Get shared exports from cache for this route + const baseFilename = id.split('?')[0]! + const sharedExports = sharedExportsCache.get(baseFilename) + const result = compileCodeSplitVirtualRoute({ code, filename: id, splitTargets: grouping, + sharedExports, }) if (debug) { diff --git a/packages/router-plugin/tests/code-splitter.test.ts b/packages/router-plugin/tests/code-splitter.test.ts index 6edf37b5f12..8fb0bb4da4c 100644 --- a/packages/router-plugin/tests/code-splitter.test.ts +++ b/packages/router-plugin/tests/code-splitter.test.ts @@ -52,12 +52,16 @@ describe('code-splitter works', () => { const dirs = getFrameworkDir(framework) const filenames = await readdir(dirs.files) + // Cache for shared exports per filename + const sharedExportsCache = new Map>() + it.each(filenames)( `should compile "reference" for "%s"`, async (filename) => { const file = await readFile(path.join(dirs.files, filename)) const code = file.toString() + const sharedExports = new Set() const compileResult = compileCodeSplitReferenceRoute({ code, filename, @@ -65,8 +69,14 @@ describe('code-splitter works', () => { addHmr: false, codeSplitGroupings: grouping, targetFramework: framework, + sharedExports, }) + // Cache shared exports for virtual compilation + if (sharedExports.size > 0) { + sharedExportsCache.set(filename, sharedExports) + } + await expect(compileResult?.code || code).toMatchFileSnapshot( path.join(dirs.snapshots, groupName, filename), ) @@ -79,6 +89,9 @@ describe('code-splitter works', () => { const file = await readFile(path.join(dirs.files, filename)) const code = file.toString() + // Get shared exports from cache + const sharedExports = sharedExportsCache.get(filename) + for (const targets of grouping) { const ident = createIdentifier(targets) @@ -86,6 +99,7 @@ describe('code-splitter works', () => { code, filename: `${filename}?${ident}`, splitTargets: targets, + sharedExports, }) const snapshotFilename = path.join( diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-alias-chain.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-alias-chain.tsx new file mode 100644 index 00000000000..4395b7a5bc4 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-alias-chain.tsx @@ -0,0 +1,17 @@ +console.warn("[tanstack-router] These exports from \"shared-alias-chain.tsx\" will not be code-split and will increase your bundle size:\n- alias\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-alias-chain.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Alias chain - ensure we track through aliases +const base = { + name: 'collection', + items: [] +}; +export const alias = base; +export const Route = createFileRoute('/test')({ + loader: async () => { + return alias.items; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-alias-chain@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-alias-chain@component.tsx new file mode 100644 index 00000000000..e2a6512a1f5 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-alias-chain@component.tsx @@ -0,0 +1,5 @@ +import { alias } from "shared-alias-chain.tsx"; // Alias chain - ensure we track through aliases +function TestComponent() { + return
{alias.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-alias-chain@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-alias-chain@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-alias-chain@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-alias-chain@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-already-exported.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-already-exported.tsx new file mode 100644 index 00000000000..de8ca211ed6 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-already-exported.tsx @@ -0,0 +1,19 @@ +console.warn("[tanstack-router] These exports from \"shared-already-exported.tsx\" will not be code-split and will increase your bundle size:\n- collection\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-already-exported.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Already exported variable - should not be double-exported +export const collection = { + name: 'todos', + preload: async () => {} +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + await collection.preload(); + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-already-exported@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-already-exported@component.tsx new file mode 100644 index 00000000000..63fdb78e140 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-already-exported@component.tsx @@ -0,0 +1,6 @@ +// Already exported variable - should not be double-exported +import { collection } from "shared-already-exported.tsx"; +function TestComponent() { + return
{collection.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-already-exported@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-already-exported@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-already-exported@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-already-exported@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-call-expression.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-call-expression.tsx new file mode 100644 index 00000000000..aefe57dd0bc --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-call-expression.tsx @@ -0,0 +1,18 @@ +console.warn("[tanstack-router] These exports from \"shared-call-expression.tsx\" will not be code-split and will increase your bundle size:\n- collection\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-call-expression.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Call expression initializers - should still work +export const collection = { + create: (name: string) => ({ + name, + items: [] + }) +}.create('todos'); +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection.items; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-call-expression@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-call-expression@component.tsx new file mode 100644 index 00000000000..281fb56d762 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-call-expression@component.tsx @@ -0,0 +1,15 @@ +import { collection } from "shared-call-expression.tsx"; +// Call expression initializers - should still work + +const query = { + from: (table: string) => ({ + table, + filters: [] + }) +}.from('users'); +function TestComponent() { + return
+ {collection.name} - {query.table} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-call-expression@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-call-expression@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-call-expression@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-call-expression@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-destructuring.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-destructuring.tsx new file mode 100644 index 00000000000..f34d479c35e --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-destructuring.tsx @@ -0,0 +1,20 @@ +console.warn("[tanstack-router] These exports from \"shared-destructuring.tsx\" will not be code-split and will increase your bundle size:\n- apiUrl\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-destructuring.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Destructuring - ensure we promote the right binding +const cfg = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +export const { + apiUrl +} = cfg; +export const Route = createFileRoute('/test')({ + loader: async () => { + // Uses the destructured binding + return fetch(apiUrl).then(r => r.json()); + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-destructuring@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-destructuring@component.tsx new file mode 100644 index 00000000000..b7ed1ffde9b --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-destructuring@component.tsx @@ -0,0 +1,13 @@ +// Destructuring - ensure we promote the right binding +const cfg = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const { + apiUrl +} = cfg; +function TestComponent() { + // Also uses the destructured binding + return
API: {apiUrl}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-destructuring@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-destructuring@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-destructuring@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-destructuring@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment.tsx new file mode 100644 index 00000000000..4a6a9e24a73 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment.tsx @@ -0,0 +1,22 @@ +console.warn("[tanstack-router] These exports from \"shared-let-reassignment.tsx\" will not be code-split and will increase your bundle size:\n- store\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-let-reassignment.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// let with reassignment - tests live binding behavior +export let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + store.count++; + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment@component.tsx new file mode 100644 index 00000000000..cd88b5634c8 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment@component.tsx @@ -0,0 +1,12 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +function TestComponent() { + return
Count: {store.count}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment@errorComponent.tsx new file mode 100644 index 00000000000..f52dfd0d532 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment@errorComponent.tsx @@ -0,0 +1,8 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment@notFoundComponent.tsx new file mode 100644 index 00000000000..f52dfd0d532 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-let-reassignment@notFoundComponent.tsx @@ -0,0 +1,8 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable.tsx new file mode 100644 index 00000000000..05ad2325f09 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable.tsx @@ -0,0 +1,22 @@ +console.warn("[tanstack-router] These exports from \"shared-module-variable.tsx\" will not be code-split and will increase your bundle size:\n- collection\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-module-variable.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +export const collection = { + name: 'todos', + preload: async () => {} +}; // Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +export const Route = createFileRoute('/todos')({ + loader: async () => { + // Use collection in loader + await collection.preload(); + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable@component.tsx new file mode 100644 index 00000000000..33cf4220c43 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable@component.tsx @@ -0,0 +1,11 @@ +import { collection } from "shared-module-variable.tsx"; +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +function TodosComponent() { + // Use collection in component + return
{collection.name}
; +} +export { TodosComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable@errorComponent.tsx new file mode 100644 index 00000000000..98f43167ce3 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable@errorComponent.tsx @@ -0,0 +1,6 @@ +import { collection } from "shared-module-variable.tsx"; +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable@notFoundComponent.tsx new file mode 100644 index 00000000000..98f43167ce3 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-module-variable@notFoundComponent.tsx @@ -0,0 +1,6 @@ +import { collection } from "shared-module-variable.tsx"; +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-declarations.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-declarations.tsx new file mode 100644 index 00000000000..286e452afb7 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-declarations.tsx @@ -0,0 +1,16 @@ +console.warn("[tanstack-router] These exports from \"shared-multiple-declarations.tsx\" will not be code-split and will increase your bundle size:\n- collection1\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-multiple-declarations.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +export const collection1 = { + name: 'todos' +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection1.name; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-declarations@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-declarations@component.tsx new file mode 100644 index 00000000000..a61b33f2114 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-declarations@component.tsx @@ -0,0 +1,12 @@ +import { collection1 } from "shared-multiple-declarations.tsx"; +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +const collection2 = { + name: 'users' +}; +function TestComponent() { + return
+ {collection1.name} {collection2.name} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-declarations@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-declarations@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-declarations@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-declarations@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-variables.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-variables.tsx new file mode 100644 index 00000000000..c8a354de2c0 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-variables.tsx @@ -0,0 +1,24 @@ +console.warn("[tanstack-router] These exports from \"shared-multiple-variables.tsx\" will not be code-split and will increase your bundle size:\n- collection1\n- collection2\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-multiple-variables.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Multiple shared variables used by both loader and component +export const collection1 = { + name: 'todos', + preload: async () => {} +}; +export const collection2 = { + name: 'users', + preload: async () => {} +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + await collection1.preload(); + await collection2.preload(); + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-variables@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-variables@component.tsx new file mode 100644 index 00000000000..93a52cdc277 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-variables@component.tsx @@ -0,0 +1,12 @@ +import { collection1, collection2 } from "shared-multiple-variables.tsx"; +// Multiple shared variables used by both loader and component + +const config = { + apiUrl: 'http://api.com' +}; +function TestComponent() { + return
+ {collection1.name} {collection2.name} {config.apiUrl} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-variables@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-variables@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-variables@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-multiple-variables@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-closure.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-closure.tsx new file mode 100644 index 00000000000..e07e8b64724 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-closure.tsx @@ -0,0 +1,13 @@ +const $$splitComponentImporter = () => import('shared-nested-closure.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Nested closure - ensure we track through closures +const cfg = { + api: 'http://api.com' +}; +const makeLoader = () => () => cfg.api; +export const Route = createFileRoute('/test')({ + loader: makeLoader(), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-closure@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-closure@component.tsx new file mode 100644 index 00000000000..059366b9fce --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-closure@component.tsx @@ -0,0 +1,6 @@ +// Nested closure - ensure we track through closures +const cfg = { + api: 'http://api.com' +}; +const Component = () =>
{cfg.api}
; +export { Component as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-closure@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-closure@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-closure@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-closure@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-function-usage.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-function-usage.tsx new file mode 100644 index 00000000000..0355c697fcf --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-function-usage.tsx @@ -0,0 +1,17 @@ +console.warn("[tanstack-router] These exports from \"shared-nested-function-usage.tsx\" will not be code-split and will increase your bundle size:\n- collection\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-nested-function-usage.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Variable used inside nested function +export const collection = { + name: 'todos', + items: [] +}; +function loadData() { + return collection.items; +} +export const Route = createFileRoute('/test')({ + loader: loadData, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-function-usage@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-function-usage@component.tsx new file mode 100644 index 00000000000..46c364af7fb --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-function-usage@component.tsx @@ -0,0 +1,5 @@ +import { collection } from "shared-nested-function-usage.tsx"; // Variable used inside nested function +function TestComponent() { + return
{collection.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-function-usage@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-function-usage@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-function-usage@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-nested-function-usage@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-object-with-methods.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-object-with-methods.tsx new file mode 100644 index 00000000000..6d95d6e6f42 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-object-with-methods.tsx @@ -0,0 +1,19 @@ +console.warn("[tanstack-router] These exports from \"shared-object-with-methods.tsx\" will not be code-split and will increase your bundle size:\n- api\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-object-with-methods.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Object contains methods (functions) - should still be shared as whole object +export const api = { + endpoint: 'http://api.com', + fetch: async () => ({ + data: 'loaded' + }), + cache: new Map() +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + return api.fetch(); + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-object-with-methods@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-object-with-methods@component.tsx new file mode 100644 index 00000000000..772c97f84cd --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-object-with-methods@component.tsx @@ -0,0 +1,7 @@ +import { api } from "shared-object-with-methods.tsx"; // Object contains methods (functions) - should still be shared as whole object +function TestComponent() { + return
+ {api.endpoint} - Cache size: {api.cache.size} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-object-with-methods@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-object-with-methods@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-object-with-methods@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-object-with-methods@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-partial-declarators.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-partial-declarators.tsx new file mode 100644 index 00000000000..c3fab600210 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-partial-declarators.tsx @@ -0,0 +1,19 @@ +console.warn("[tanstack-router] These exports from \"shared-partial-declarators.tsx\" will not be code-split and will increase your bundle size:\n- shared\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-partial-declarators.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +export const shared = new Map(); +export const Route = createFileRoute('/test')({ + loader: async () => { + // Only uses shared, not a + shared.set('loaded', true); + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-partial-declarators@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-partial-declarators@component.tsx new file mode 100644 index 00000000000..6e219600a61 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-partial-declarators@component.tsx @@ -0,0 +1,10 @@ +import { shared } from "shared-partial-declarators.tsx"; +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +const a = 1; +function TestComponent() { + // Uses both shared and a + return
Count: {shared.size + a}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-partial-declarators@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-partial-declarators@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-partial-declarators@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-partial-declarators@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-variable-dependency.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-variable-dependency.tsx new file mode 100644 index 00000000000..38ea19f9391 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-variable-dependency.tsx @@ -0,0 +1,20 @@ +console.warn("[tanstack-router] These exports from \"shared-variable-dependency.tsx\" will not be code-split and will increase your bundle size:\n- collection\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-variable-dependency.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Variable references another shared variable +const baseConfig = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +export const collection = { + config: baseConfig, + name: 'todos' +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection.name; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-variable-dependency@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-variable-dependency@component.tsx new file mode 100644 index 00000000000..aa18e68770e --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-variable-dependency@component.tsx @@ -0,0 +1,12 @@ +import { collection } from "shared-variable-dependency.tsx"; +// Variable references another shared variable +const baseConfig = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +function TestComponent() { + return
+ {collection.name} - {baseConfig.apiUrl} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-variable-dependency@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-variable-dependency@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-variable-dependency@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/shared-variable-dependency@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable.tsx new file mode 100644 index 00000000000..15b4e9d9741 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable.tsx @@ -0,0 +1,17 @@ +const $$splitComponentImporter = () => import('split-only-variable.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +export const Route = createFileRoute('/test')({ + loader: async () => { + // Loader doesn't use onlySplit at all + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable@component.tsx new file mode 100644 index 00000000000..761bb11e737 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable@component.tsx @@ -0,0 +1,9 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +function TestComponent() { + // Only component uses onlySplit + return
Size: {onlySplit.size}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable@errorComponent.tsx new file mode 100644 index 00000000000..90e58d835af --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable@errorComponent.tsx @@ -0,0 +1,4 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable@notFoundComponent.tsx new file mode 100644 index 00000000000..90e58d835af --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/1-default/split-only-variable@notFoundComponent.tsx @@ -0,0 +1,4 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-alias-chain.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-alias-chain.tsx new file mode 100644 index 00000000000..efb3316c999 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-alias-chain.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-alias-chain.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-alias-chain.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Alias chain - ensure we track through aliases + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-alias-chain@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-alias-chain@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..a96a444daf7 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-alias-chain@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,10 @@ +// Alias chain - ensure we track through aliases +const base = { + name: 'collection', + items: [] +}; +const alias = base; +function TestComponent() { + return
{alias.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-alias-chain@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-alias-chain@loader.tsx new file mode 100644 index 00000000000..a5d32cf40db --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-alias-chain@loader.tsx @@ -0,0 +1,10 @@ +// Alias chain - ensure we track through aliases +const base = { + name: 'collection', + items: [] +}; +const alias = base; +const SplitLoader = async () => { + return alias.items; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-already-exported.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-already-exported.tsx new file mode 100644 index 00000000000..c89424ed81c --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-already-exported.tsx @@ -0,0 +1,15 @@ +const $$splitComponentImporter = () => import('shared-already-exported.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-already-exported.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Already exported variable - should not be double-exported +export const collection = { + name: 'todos', + preload: async () => {} +}; +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-already-exported@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-already-exported@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..63fdb78e140 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-already-exported@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,6 @@ +// Already exported variable - should not be double-exported +import { collection } from "shared-already-exported.tsx"; +function TestComponent() { + return
{collection.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-already-exported@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-already-exported@loader.tsx new file mode 100644 index 00000000000..f7ef905c211 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-already-exported@loader.tsx @@ -0,0 +1,9 @@ +// Already exported variable - should not be double-exported +import { collection } from "shared-already-exported.tsx"; +const SplitLoader = async () => { + await collection.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-call-expression.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-call-expression.tsx new file mode 100644 index 00000000000..6d55e663a0f --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-call-expression.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-call-expression.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-call-expression.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Call expression initializers - should still work + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-call-expression@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-call-expression@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..b0932a66400 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-call-expression@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,19 @@ +// Call expression initializers - should still work +const collection = { + create: (name: string) => ({ + name, + items: [] + }) +}.create('todos'); +const query = { + from: (table: string) => ({ + table, + filters: [] + }) +}.from('users'); +function TestComponent() { + return
+ {collection.name} - {query.table} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-call-expression@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-call-expression@loader.tsx new file mode 100644 index 00000000000..a1e4838a861 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-call-expression@loader.tsx @@ -0,0 +1,11 @@ +// Call expression initializers - should still work +const collection = { + create: (name: string) => ({ + name, + items: [] + }) +}.create('todos'); +const SplitLoader = async () => { + return collection.items; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-destructuring.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-destructuring.tsx new file mode 100644 index 00000000000..92ccb309bde --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-destructuring.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-destructuring.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-destructuring.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Destructuring - ensure we promote the right binding + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-destructuring@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-destructuring@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..b7ed1ffde9b --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-destructuring@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,13 @@ +// Destructuring - ensure we promote the right binding +const cfg = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const { + apiUrl +} = cfg; +function TestComponent() { + // Also uses the destructured binding + return
API: {apiUrl}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-destructuring@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-destructuring@loader.tsx new file mode 100644 index 00000000000..6c138455e6b --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-destructuring@loader.tsx @@ -0,0 +1,13 @@ +// Destructuring - ensure we promote the right binding +const cfg = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const { + apiUrl +} = cfg; +const SplitLoader = async () => { + // Uses the destructured binding + return fetch(apiUrl).then(r => r.json()); +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment.tsx new file mode 100644 index 00000000000..b3db8b7b88a --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment.tsx @@ -0,0 +1,18 @@ +const $$splitComponentImporter = () => import('shared-let-reassignment.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-let-reassignment.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..cd88b5634c8 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,12 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +function TestComponent() { + return
Count: {store.count}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment@component.tsx new file mode 100644 index 00000000000..f397a814ed8 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment@component.tsx @@ -0,0 +1,12 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +function TestComponent() { + return
Count: {store.count}
; +} +export { TestComponent as component }; diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment@loader.tsx new file mode 100644 index 00000000000..89f2fced8d8 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-let-reassignment@loader.tsx @@ -0,0 +1,15 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +const SplitLoader = async () => { + store.count++; + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-module-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-module-variable.tsx new file mode 100644 index 00000000000..c3e12a06003 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-module-variable.tsx @@ -0,0 +1,19 @@ +const $$splitComponentImporter = () => import('shared-module-variable.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-module-variable.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +export const Route = createFileRoute('/todos')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-module-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-module-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..f53fff41701 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-module-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,14 @@ +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +function TodosComponent() { + // Use collection in component + return
{collection.name}
; +} +export { TodosComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-module-variable@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-module-variable@loader.tsx new file mode 100644 index 00000000000..1d52dc1b192 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-module-variable@loader.tsx @@ -0,0 +1,17 @@ +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +const SplitLoader = async () => { + // Use collection in loader + await collection.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-declarations.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-declarations.tsx new file mode 100644 index 00000000000..8240bc8b44a --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-declarations.tsx @@ -0,0 +1,13 @@ +const $$splitComponentImporter = () => import('shared-multiple-declarations.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-multiple-declarations.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-declarations@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-declarations@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..c103abe982e --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-declarations@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,14 @@ +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +const collection1 = { + name: 'todos' + }, + collection2 = { + name: 'users' + }; +function TestComponent() { + return
+ {collection1.name} {collection2.name} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-declarations@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-declarations@loader.tsx new file mode 100644 index 00000000000..ffa805a6f6e --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-declarations@loader.tsx @@ -0,0 +1,9 @@ +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +const collection1 = { + name: 'todos' +}; +const SplitLoader = async () => { + return collection1.name; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-variables.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-variables.tsx new file mode 100644 index 00000000000..669474c5ba1 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-variables.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-multiple-variables.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-multiple-variables.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Multiple shared variables used by both loader and component + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-variables@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-variables@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..6bd0c027294 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-variables@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,18 @@ +// Multiple shared variables used by both loader and component +const collection1 = { + name: 'todos', + preload: async () => {} +}; +const collection2 = { + name: 'users', + preload: async () => {} +}; +const config = { + apiUrl: 'http://api.com' +}; +function TestComponent() { + return
+ {collection1.name} {collection2.name} {config.apiUrl} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-variables@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-variables@loader.tsx new file mode 100644 index 00000000000..3a65c044151 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-multiple-variables@loader.tsx @@ -0,0 +1,17 @@ +// Multiple shared variables used by both loader and component +const collection1 = { + name: 'todos', + preload: async () => {} +}; +const collection2 = { + name: 'users', + preload: async () => {} +}; +const SplitLoader = async () => { + await collection1.preload(); + await collection2.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-closure.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-closure.tsx new file mode 100644 index 00000000000..e873905549a --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-closure.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-nested-closure.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-nested-closure.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Nested closure - ensure we track through closures + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-closure@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-closure@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..059366b9fce --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-closure@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,6 @@ +// Nested closure - ensure we track through closures +const cfg = { + api: 'http://api.com' +}; +const Component = () =>
{cfg.api}
; +export { Component as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-closure@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-closure@loader.tsx new file mode 100644 index 00000000000..f1cd7767dbb --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-closure@loader.tsx @@ -0,0 +1,7 @@ +// Nested closure - ensure we track through closures +const cfg = { + api: 'http://api.com' +}; +const makeLoader = () => () => cfg.api; +const SplitLoader = makeLoader(); +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-function-usage.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-function-usage.tsx new file mode 100644 index 00000000000..01ac35d82e3 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-function-usage.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-nested-function-usage.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-nested-function-usage.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Variable used inside nested function + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-function-usage@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-function-usage@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..247601d8ec3 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-function-usage@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,9 @@ +// Variable used inside nested function +const collection = { + name: 'todos', + items: [] +}; +function TestComponent() { + return
{collection.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-function-usage@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-function-usage@loader.tsx new file mode 100644 index 00000000000..78b8d0a7e47 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-nested-function-usage@loader.tsx @@ -0,0 +1,9 @@ +// Variable used inside nested function +const collection = { + name: 'todos', + items: [] +}; +function loadData() { + return collection.items; +} +export { loadData as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-object-with-methods.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-object-with-methods.tsx new file mode 100644 index 00000000000..df75c09e0f3 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-object-with-methods.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-object-with-methods.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-object-with-methods.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Object contains methods (functions) - should still be shared as whole object + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-object-with-methods@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-object-with-methods@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..0b87b4d5576 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-object-with-methods@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,14 @@ +// Object contains methods (functions) - should still be shared as whole object +const api = { + endpoint: 'http://api.com', + fetch: async () => ({ + data: 'loaded' + }), + cache: new Map() +}; +function TestComponent() { + return
+ {api.endpoint} - Cache size: {api.cache.size} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-object-with-methods@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-object-with-methods@loader.tsx new file mode 100644 index 00000000000..53f950387de --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-object-with-methods@loader.tsx @@ -0,0 +1,12 @@ +// Object contains methods (functions) - should still be shared as whole object +const api = { + endpoint: 'http://api.com', + fetch: async () => ({ + data: 'loaded' + }), + cache: new Map() +}; +const SplitLoader = async () => { + return api.fetch(); +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-partial-declarators.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-partial-declarators.tsx new file mode 100644 index 00000000000..41e0d88e0bd --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-partial-declarators.tsx @@ -0,0 +1,14 @@ +const $$splitComponentImporter = () => import('shared-partial-declarators.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-partial-declarators.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-partial-declarators@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-partial-declarators@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..a6005a94bb0 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-partial-declarators@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,10 @@ +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +const a = 1, + shared = new Map(); +function TestComponent() { + // Uses both shared and a + return
Count: {shared.size + a}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-partial-declarators@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-partial-declarators@loader.tsx new file mode 100644 index 00000000000..3a13615d89c --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-partial-declarators@loader.tsx @@ -0,0 +1,12 @@ +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +const shared = new Map(); +const SplitLoader = async () => { + // Only uses shared, not a + shared.set('loaded', true); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-variable-dependency.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-variable-dependency.tsx new file mode 100644 index 00000000000..3d4e6c65f50 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-variable-dependency.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-variable-dependency.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-variable-dependency.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Variable references another shared variable + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-variable-dependency@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-variable-dependency@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..fe734a45d03 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-variable-dependency@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,15 @@ +// Variable references another shared variable +const baseConfig = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const collection = { + config: baseConfig, + name: 'todos' +}; +function TestComponent() { + return
+ {collection.name} - {baseConfig.apiUrl} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-variable-dependency@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-variable-dependency@loader.tsx new file mode 100644 index 00000000000..742f37595ce --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/shared-variable-dependency@loader.tsx @@ -0,0 +1,13 @@ +// Variable references another shared variable +const baseConfig = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const collection = { + config: baseConfig, + name: 'todos' +}; +const SplitLoader = async () => { + return collection.name; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/split-only-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/split-only-variable.tsx new file mode 100644 index 00000000000..6a4fc208806 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/split-only-variable.tsx @@ -0,0 +1,14 @@ +const $$splitComponentImporter = () => import('split-only-variable.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('split-only-variable.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/split-only-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/split-only-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..761bb11e737 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/split-only-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,9 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +function TestComponent() { + // Only component uses onlySplit + return
Size: {onlySplit.size}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/split-only-variable@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/split-only-variable@loader.tsx new file mode 100644 index 00000000000..90e112ef6a2 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/2-components-combined-loader-separate/split-only-variable@loader.tsx @@ -0,0 +1,11 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +const SplitLoader = async () => { + // Loader doesn't use onlySplit at all + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-alias-chain.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-alias-chain.tsx new file mode 100644 index 00000000000..a0eb0c62d25 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-alias-chain.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-alias-chain.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-alias-chain.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Alias chain - ensure we track through aliases + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-alias-chain@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-alias-chain@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..24a3a8ad678 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-alias-chain@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,14 @@ +// Alias chain - ensure we track through aliases +const base = { + name: 'collection', + items: [] +}; +const alias = base; +function TestComponent() { + return
{alias.name}
; +} +const SplitLoader = async () => { + return alias.items; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-alias-chain@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-alias-chain@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-already-exported.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-already-exported.tsx new file mode 100644 index 00000000000..a4199e94e08 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-already-exported.tsx @@ -0,0 +1,15 @@ +const $$splitComponentImporter = () => import('shared-already-exported.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-already-exported.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Already exported variable - should not be double-exported +export const collection = { + name: 'todos', + preload: async () => {} +}; +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-already-exported@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-already-exported@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..cdc0d4c02e0 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-already-exported@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,13 @@ +// Already exported variable - should not be double-exported +import { collection } from "shared-already-exported.tsx"; +function TestComponent() { + return
{collection.name}
; +} +const SplitLoader = async () => { + await collection.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-already-exported@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-already-exported@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-call-expression.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-call-expression.tsx new file mode 100644 index 00000000000..f12354b301b --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-call-expression.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-call-expression.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-call-expression.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Call expression initializers - should still work + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-call-expression@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-call-expression@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..d2ddb0ff86f --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-call-expression@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,23 @@ +// Call expression initializers - should still work +const collection = { + create: (name: string) => ({ + name, + items: [] + }) +}.create('todos'); +const query = { + from: (table: string) => ({ + table, + filters: [] + }) +}.from('users'); +function TestComponent() { + return
+ {collection.name} - {query.table} +
; +} +const SplitLoader = async () => { + return collection.items; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-call-expression@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-call-expression@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-destructuring.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-destructuring.tsx new file mode 100644 index 00000000000..e77ac20725e --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-destructuring.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-destructuring.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-destructuring.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Destructuring - ensure we promote the right binding + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-destructuring@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-destructuring@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..03625751b13 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-destructuring@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,18 @@ +// Destructuring - ensure we promote the right binding +const cfg = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const { + apiUrl +} = cfg; +function TestComponent() { + // Also uses the destructured binding + return
API: {apiUrl}
; +} +const SplitLoader = async () => { + // Uses the destructured binding + return fetch(apiUrl).then(r => r.json()); +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-destructuring@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-destructuring@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-let-reassignment.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-let-reassignment.tsx new file mode 100644 index 00000000000..f0c0030e4a7 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-let-reassignment.tsx @@ -0,0 +1,18 @@ +const $$splitComponentImporter = () => import('shared-let-reassignment.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-let-reassignment.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-let-reassignment@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-let-reassignment@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..ba7c72d7121 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-let-reassignment@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,19 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +function TestComponent() { + return
Count: {store.count}
; +} +const SplitLoader = async () => { + store.count++; + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-let-reassignment@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-let-reassignment@errorComponent.tsx new file mode 100644 index 00000000000..f52dfd0d532 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-let-reassignment@errorComponent.tsx @@ -0,0 +1,8 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-module-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-module-variable.tsx new file mode 100644 index 00000000000..2d4eb74e763 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-module-variable.tsx @@ -0,0 +1,19 @@ +const $$splitComponentImporter = () => import('shared-module-variable.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-module-variable.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +export const Route = createFileRoute('/todos')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-module-variable@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-module-variable@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..4b28c46a7b0 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-module-variable@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,22 @@ +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +function TodosComponent() { + // Use collection in component + return
{collection.name}
; +} +const SplitLoader = async () => { + // Use collection in loader + await collection.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TodosComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-module-variable@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-module-variable@errorComponent.tsx new file mode 100644 index 00000000000..caf87ba5c8d --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-module-variable@errorComponent.tsx @@ -0,0 +1,9 @@ +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-declarations.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-declarations.tsx new file mode 100644 index 00000000000..4e7a2238af6 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-declarations.tsx @@ -0,0 +1,13 @@ +const $$splitComponentImporter = () => import('shared-multiple-declarations.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-multiple-declarations.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-declarations@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-declarations@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..dbc75a6caf9 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-declarations@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,18 @@ +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +const collection1 = { + name: 'todos' + }, + collection2 = { + name: 'users' + }; +function TestComponent() { + return
+ {collection1.name} {collection2.name} +
; +} +const SplitLoader = async () => { + return collection1.name; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-declarations@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-declarations@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-variables.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-variables.tsx new file mode 100644 index 00000000000..4daa2f2ea77 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-variables.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-multiple-variables.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-multiple-variables.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Multiple shared variables used by both loader and component + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-variables@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-variables@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..9c780d4347d --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-variables@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,26 @@ +// Multiple shared variables used by both loader and component +const collection1 = { + name: 'todos', + preload: async () => {} +}; +const collection2 = { + name: 'users', + preload: async () => {} +}; +const config = { + apiUrl: 'http://api.com' +}; +function TestComponent() { + return
+ {collection1.name} {collection2.name} {config.apiUrl} +
; +} +const SplitLoader = async () => { + await collection1.preload(); + await collection2.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-variables@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-multiple-variables@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-closure.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-closure.tsx new file mode 100644 index 00000000000..a590a5534fe --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-closure.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-nested-closure.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-nested-closure.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Nested closure - ensure we track through closures + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-closure@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-closure@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..dc28c14a14a --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-closure@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,9 @@ +// Nested closure - ensure we track through closures +const cfg = { + api: 'http://api.com' +}; +const makeLoader = () => () => cfg.api; +const Component = () =>
{cfg.api}
; +const SplitLoader = makeLoader(); +export { SplitLoader as loader }; +export { Component as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-closure@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-closure@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-function-usage.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-function-usage.tsx new file mode 100644 index 00000000000..e39c1fdfc68 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-function-usage.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-nested-function-usage.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-nested-function-usage.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Variable used inside nested function + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-function-usage@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-function-usage@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..720598b13bd --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-function-usage@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,13 @@ +// Variable used inside nested function +const collection = { + name: 'todos', + items: [] +}; +function loadData() { + return collection.items; +} +function TestComponent() { + return
{collection.name}
; +} +export { loadData as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-function-usage@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-nested-function-usage@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-object-with-methods.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-object-with-methods.tsx new file mode 100644 index 00000000000..710c59abb89 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-object-with-methods.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-object-with-methods.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-object-with-methods.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Object contains methods (functions) - should still be shared as whole object + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-object-with-methods@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-object-with-methods@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..7ee457ba36d --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-object-with-methods@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,18 @@ +// Object contains methods (functions) - should still be shared as whole object +const api = { + endpoint: 'http://api.com', + fetch: async () => ({ + data: 'loaded' + }), + cache: new Map() +}; +function TestComponent() { + return
+ {api.endpoint} - Cache size: {api.cache.size} +
; +} +const SplitLoader = async () => { + return api.fetch(); +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-object-with-methods@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-object-with-methods@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-partial-declarators.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-partial-declarators.tsx new file mode 100644 index 00000000000..341ab920e8b --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-partial-declarators.tsx @@ -0,0 +1,14 @@ +const $$splitComponentImporter = () => import('shared-partial-declarators.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-partial-declarators.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-partial-declarators@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-partial-declarators@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..2fe8995815d --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-partial-declarators@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,18 @@ +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +const a = 1, + shared = new Map(); +function TestComponent() { + // Uses both shared and a + return
Count: {shared.size + a}
; +} +const SplitLoader = async () => { + // Only uses shared, not a + shared.set('loaded', true); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-partial-declarators@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-partial-declarators@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-variable-dependency.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-variable-dependency.tsx new file mode 100644 index 00000000000..3acd8108140 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-variable-dependency.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-variable-dependency.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('shared-variable-dependency.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Variable references another shared variable + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-variable-dependency@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-variable-dependency@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..eec1a99efa2 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-variable-dependency@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,19 @@ +// Variable references another shared variable +const baseConfig = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const collection = { + config: baseConfig, + name: 'todos' +}; +function TestComponent() { + return
+ {collection.name} - {baseConfig.apiUrl} +
; +} +const SplitLoader = async () => { + return collection.name; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-variable-dependency@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/shared-variable-dependency@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/split-only-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/split-only-variable.tsx new file mode 100644 index 00000000000..75a15b9b44c --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/split-only-variable.tsx @@ -0,0 +1,14 @@ +const $$splitComponentImporter = () => import('split-only-variable.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/react-router'; +const $$splitLoaderImporter = () => import('split-only-variable.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/react-router'; +import { createFileRoute } from '@tanstack/react-router'; + +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/split-only-variable@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/split-only-variable@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..65dfd7c5ca0 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/split-only-variable@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,16 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +function TestComponent() { + // Only component uses onlySplit + return
Size: {onlySplit.size}
; +} +const SplitLoader = async () => { + // Loader doesn't use onlySplit at all + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/split-only-variable@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/split-only-variable@errorComponent.tsx new file mode 100644 index 00000000000..90e58d835af --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/react/3-all-combined-errorComponent-separate/split-only-variable@errorComponent.tsx @@ -0,0 +1,4 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-alias-chain.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-alias-chain.tsx new file mode 100644 index 00000000000..182c71ad9cf --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-alias-chain.tsx @@ -0,0 +1,17 @@ +console.warn("[tanstack-router] These exports from \"shared-alias-chain.tsx\" will not be code-split and will increase your bundle size:\n- alias\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-alias-chain.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Alias chain - ensure we track through aliases +const base = { + name: 'collection', + items: [] +}; +export const alias = base; +export const Route = createFileRoute('/test')({ + loader: async () => { + return alias.items; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-alias-chain@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-alias-chain@component.tsx new file mode 100644 index 00000000000..e2a6512a1f5 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-alias-chain@component.tsx @@ -0,0 +1,5 @@ +import { alias } from "shared-alias-chain.tsx"; // Alias chain - ensure we track through aliases +function TestComponent() { + return
{alias.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-alias-chain@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-alias-chain@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-alias-chain@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-alias-chain@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-already-exported.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-already-exported.tsx new file mode 100644 index 00000000000..51905847581 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-already-exported.tsx @@ -0,0 +1,19 @@ +console.warn("[tanstack-router] These exports from \"shared-already-exported.tsx\" will not be code-split and will increase your bundle size:\n- collection\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-already-exported.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Already exported variable - should not be double-exported +export const collection = { + name: 'todos', + preload: async () => {} +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + await collection.preload(); + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-already-exported@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-already-exported@component.tsx new file mode 100644 index 00000000000..63fdb78e140 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-already-exported@component.tsx @@ -0,0 +1,6 @@ +// Already exported variable - should not be double-exported +import { collection } from "shared-already-exported.tsx"; +function TestComponent() { + return
{collection.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-already-exported@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-already-exported@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-already-exported@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-already-exported@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-call-expression.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-call-expression.tsx new file mode 100644 index 00000000000..fb3b19b9da0 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-call-expression.tsx @@ -0,0 +1,18 @@ +console.warn("[tanstack-router] These exports from \"shared-call-expression.tsx\" will not be code-split and will increase your bundle size:\n- collection\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-call-expression.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Call expression initializers - should still work +export const collection = { + create: (name: string) => ({ + name, + items: [] + }) +}.create('todos'); +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection.items; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-call-expression@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-call-expression@component.tsx new file mode 100644 index 00000000000..281fb56d762 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-call-expression@component.tsx @@ -0,0 +1,15 @@ +import { collection } from "shared-call-expression.tsx"; +// Call expression initializers - should still work + +const query = { + from: (table: string) => ({ + table, + filters: [] + }) +}.from('users'); +function TestComponent() { + return
+ {collection.name} - {query.table} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-call-expression@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-call-expression@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-call-expression@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-call-expression@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-destructuring.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-destructuring.tsx new file mode 100644 index 00000000000..53a8593de42 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-destructuring.tsx @@ -0,0 +1,20 @@ +console.warn("[tanstack-router] These exports from \"shared-destructuring.tsx\" will not be code-split and will increase your bundle size:\n- apiUrl\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-destructuring.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Destructuring - ensure we promote the right binding +const cfg = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +export const { + apiUrl +} = cfg; +export const Route = createFileRoute('/test')({ + loader: async () => { + // Uses the destructured binding + return fetch(apiUrl).then(r => r.json()); + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-destructuring@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-destructuring@component.tsx new file mode 100644 index 00000000000..b7ed1ffde9b --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-destructuring@component.tsx @@ -0,0 +1,13 @@ +// Destructuring - ensure we promote the right binding +const cfg = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const { + apiUrl +} = cfg; +function TestComponent() { + // Also uses the destructured binding + return
API: {apiUrl}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-destructuring@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-destructuring@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-destructuring@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-destructuring@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment.tsx new file mode 100644 index 00000000000..52d0e59748c --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment.tsx @@ -0,0 +1,22 @@ +console.warn("[tanstack-router] These exports from \"shared-let-reassignment.tsx\" will not be code-split and will increase your bundle size:\n- store\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-let-reassignment.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// let with reassignment - tests live binding behavior +export let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + store.count++; + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment@component.tsx new file mode 100644 index 00000000000..cd88b5634c8 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment@component.tsx @@ -0,0 +1,12 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +function TestComponent() { + return
Count: {store.count}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment@errorComponent.tsx new file mode 100644 index 00000000000..f52dfd0d532 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment@errorComponent.tsx @@ -0,0 +1,8 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment@notFoundComponent.tsx new file mode 100644 index 00000000000..f52dfd0d532 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-let-reassignment@notFoundComponent.tsx @@ -0,0 +1,8 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable.tsx new file mode 100644 index 00000000000..dde12e452f3 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable.tsx @@ -0,0 +1,22 @@ +console.warn("[tanstack-router] These exports from \"shared-module-variable.tsx\" will not be code-split and will increase your bundle size:\n- collection\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-module-variable.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +export const collection = { + name: 'todos', + preload: async () => {} +}; // Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +export const Route = createFileRoute('/todos')({ + loader: async () => { + // Use collection in loader + await collection.preload(); + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable@component.tsx new file mode 100644 index 00000000000..33cf4220c43 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable@component.tsx @@ -0,0 +1,11 @@ +import { collection } from "shared-module-variable.tsx"; +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +function TodosComponent() { + // Use collection in component + return
{collection.name}
; +} +export { TodosComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable@errorComponent.tsx new file mode 100644 index 00000000000..98f43167ce3 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable@errorComponent.tsx @@ -0,0 +1,6 @@ +import { collection } from "shared-module-variable.tsx"; +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable@notFoundComponent.tsx new file mode 100644 index 00000000000..98f43167ce3 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-module-variable@notFoundComponent.tsx @@ -0,0 +1,6 @@ +import { collection } from "shared-module-variable.tsx"; +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-declarations.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-declarations.tsx new file mode 100644 index 00000000000..0b1f0a84a1a --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-declarations.tsx @@ -0,0 +1,16 @@ +console.warn("[tanstack-router] These exports from \"shared-multiple-declarations.tsx\" will not be code-split and will increase your bundle size:\n- collection1\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-multiple-declarations.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +export const collection1 = { + name: 'todos' +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection1.name; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-declarations@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-declarations@component.tsx new file mode 100644 index 00000000000..a61b33f2114 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-declarations@component.tsx @@ -0,0 +1,12 @@ +import { collection1 } from "shared-multiple-declarations.tsx"; +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +const collection2 = { + name: 'users' +}; +function TestComponent() { + return
+ {collection1.name} {collection2.name} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-declarations@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-declarations@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-declarations@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-declarations@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-variables.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-variables.tsx new file mode 100644 index 00000000000..7e49bce9376 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-variables.tsx @@ -0,0 +1,24 @@ +console.warn("[tanstack-router] These exports from \"shared-multiple-variables.tsx\" will not be code-split and will increase your bundle size:\n- collection1\n- collection2\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-multiple-variables.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Multiple shared variables used by both loader and component +export const collection1 = { + name: 'todos', + preload: async () => {} +}; +export const collection2 = { + name: 'users', + preload: async () => {} +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + await collection1.preload(); + await collection2.preload(); + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-variables@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-variables@component.tsx new file mode 100644 index 00000000000..93a52cdc277 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-variables@component.tsx @@ -0,0 +1,12 @@ +import { collection1, collection2 } from "shared-multiple-variables.tsx"; +// Multiple shared variables used by both loader and component + +const config = { + apiUrl: 'http://api.com' +}; +function TestComponent() { + return
+ {collection1.name} {collection2.name} {config.apiUrl} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-variables@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-variables@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-variables@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-multiple-variables@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-closure.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-closure.tsx new file mode 100644 index 00000000000..f4919a88723 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-closure.tsx @@ -0,0 +1,13 @@ +const $$splitComponentImporter = () => import('shared-nested-closure.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Nested closure - ensure we track through closures +const cfg = { + api: 'http://api.com' +}; +const makeLoader = () => () => cfg.api; +export const Route = createFileRoute('/test')({ + loader: makeLoader(), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-closure@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-closure@component.tsx new file mode 100644 index 00000000000..059366b9fce --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-closure@component.tsx @@ -0,0 +1,6 @@ +// Nested closure - ensure we track through closures +const cfg = { + api: 'http://api.com' +}; +const Component = () =>
{cfg.api}
; +export { Component as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-closure@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-closure@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-closure@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-closure@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-function-usage.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-function-usage.tsx new file mode 100644 index 00000000000..a71dd5f9074 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-function-usage.tsx @@ -0,0 +1,17 @@ +console.warn("[tanstack-router] These exports from \"shared-nested-function-usage.tsx\" will not be code-split and will increase your bundle size:\n- collection\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-nested-function-usage.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Variable used inside nested function +export const collection = { + name: 'todos', + items: [] +}; +function loadData() { + return collection.items; +} +export const Route = createFileRoute('/test')({ + loader: loadData, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-function-usage@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-function-usage@component.tsx new file mode 100644 index 00000000000..46c364af7fb --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-function-usage@component.tsx @@ -0,0 +1,5 @@ +import { collection } from "shared-nested-function-usage.tsx"; // Variable used inside nested function +function TestComponent() { + return
{collection.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-function-usage@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-function-usage@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-function-usage@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-nested-function-usage@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-object-with-methods.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-object-with-methods.tsx new file mode 100644 index 00000000000..cc655ca7829 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-object-with-methods.tsx @@ -0,0 +1,19 @@ +console.warn("[tanstack-router] These exports from \"shared-object-with-methods.tsx\" will not be code-split and will increase your bundle size:\n- api\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-object-with-methods.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Object contains methods (functions) - should still be shared as whole object +export const api = { + endpoint: 'http://api.com', + fetch: async () => ({ + data: 'loaded' + }), + cache: new Map() +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + return api.fetch(); + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-object-with-methods@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-object-with-methods@component.tsx new file mode 100644 index 00000000000..772c97f84cd --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-object-with-methods@component.tsx @@ -0,0 +1,7 @@ +import { api } from "shared-object-with-methods.tsx"; // Object contains methods (functions) - should still be shared as whole object +function TestComponent() { + return
+ {api.endpoint} - Cache size: {api.cache.size} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-object-with-methods@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-object-with-methods@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-object-with-methods@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-object-with-methods@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-partial-declarators.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-partial-declarators.tsx new file mode 100644 index 00000000000..4ed3c8ddab2 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-partial-declarators.tsx @@ -0,0 +1,19 @@ +console.warn("[tanstack-router] These exports from \"shared-partial-declarators.tsx\" will not be code-split and will increase your bundle size:\n- shared\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-partial-declarators.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +export const shared = new Map(); +export const Route = createFileRoute('/test')({ + loader: async () => { + // Only uses shared, not a + shared.set('loaded', true); + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-partial-declarators@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-partial-declarators@component.tsx new file mode 100644 index 00000000000..6e219600a61 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-partial-declarators@component.tsx @@ -0,0 +1,10 @@ +import { shared } from "shared-partial-declarators.tsx"; +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +const a = 1; +function TestComponent() { + // Uses both shared and a + return
Count: {shared.size + a}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-partial-declarators@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-partial-declarators@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-partial-declarators@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-partial-declarators@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-variable-dependency.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-variable-dependency.tsx new file mode 100644 index 00000000000..79175de4879 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-variable-dependency.tsx @@ -0,0 +1,20 @@ +console.warn("[tanstack-router] These exports from \"shared-variable-dependency.tsx\" will not be code-split and will increase your bundle size:\n- collection\nFor the best optimization, these items should either have their export statements removed, or be imported from another location that is not a route file."); +const $$splitComponentImporter = () => import('shared-variable-dependency.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Variable references another shared variable +const baseConfig = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +export const collection = { + config: baseConfig, + name: 'todos' +}; +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection.name; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-variable-dependency@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-variable-dependency@component.tsx new file mode 100644 index 00000000000..aa18e68770e --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-variable-dependency@component.tsx @@ -0,0 +1,12 @@ +import { collection } from "shared-variable-dependency.tsx"; +// Variable references another shared variable +const baseConfig = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +function TestComponent() { + return
+ {collection.name} - {baseConfig.apiUrl} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-variable-dependency@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-variable-dependency@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-variable-dependency@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/shared-variable-dependency@notFoundComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable.tsx new file mode 100644 index 00000000000..5741c5c0b59 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable.tsx @@ -0,0 +1,17 @@ +const $$splitComponentImporter = () => import('split-only-variable.tsx?tsr-split=component'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +export const Route = createFileRoute('/test')({ + loader: async () => { + // Loader doesn't use onlySplit at all + return { + data: 'loaded' + }; + }, + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable@component.tsx new file mode 100644 index 00000000000..761bb11e737 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable@component.tsx @@ -0,0 +1,9 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +function TestComponent() { + // Only component uses onlySplit + return
Size: {onlySplit.size}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable@errorComponent.tsx new file mode 100644 index 00000000000..90e58d835af --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable@errorComponent.tsx @@ -0,0 +1,4 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable@notFoundComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable@notFoundComponent.tsx new file mode 100644 index 00000000000..90e58d835af --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/1-default/split-only-variable@notFoundComponent.tsx @@ -0,0 +1,4 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-alias-chain.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-alias-chain.tsx new file mode 100644 index 00000000000..5e5a8775e03 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-alias-chain.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-alias-chain.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-alias-chain.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Alias chain - ensure we track through aliases + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-alias-chain@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-alias-chain@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..a96a444daf7 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-alias-chain@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,10 @@ +// Alias chain - ensure we track through aliases +const base = { + name: 'collection', + items: [] +}; +const alias = base; +function TestComponent() { + return
{alias.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-alias-chain@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-alias-chain@loader.tsx new file mode 100644 index 00000000000..a5d32cf40db --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-alias-chain@loader.tsx @@ -0,0 +1,10 @@ +// Alias chain - ensure we track through aliases +const base = { + name: 'collection', + items: [] +}; +const alias = base; +const SplitLoader = async () => { + return alias.items; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-already-exported.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-already-exported.tsx new file mode 100644 index 00000000000..ff00100e3df --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-already-exported.tsx @@ -0,0 +1,15 @@ +const $$splitComponentImporter = () => import('shared-already-exported.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-already-exported.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Already exported variable - should not be double-exported +export const collection = { + name: 'todos', + preload: async () => {} +}; +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-already-exported@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-already-exported@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..63fdb78e140 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-already-exported@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,6 @@ +// Already exported variable - should not be double-exported +import { collection } from "shared-already-exported.tsx"; +function TestComponent() { + return
{collection.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-already-exported@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-already-exported@loader.tsx new file mode 100644 index 00000000000..f7ef905c211 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-already-exported@loader.tsx @@ -0,0 +1,9 @@ +// Already exported variable - should not be double-exported +import { collection } from "shared-already-exported.tsx"; +const SplitLoader = async () => { + await collection.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-call-expression.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-call-expression.tsx new file mode 100644 index 00000000000..992aa50dda9 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-call-expression.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-call-expression.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-call-expression.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Call expression initializers - should still work + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-call-expression@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-call-expression@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..b0932a66400 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-call-expression@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,19 @@ +// Call expression initializers - should still work +const collection = { + create: (name: string) => ({ + name, + items: [] + }) +}.create('todos'); +const query = { + from: (table: string) => ({ + table, + filters: [] + }) +}.from('users'); +function TestComponent() { + return
+ {collection.name} - {query.table} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-call-expression@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-call-expression@loader.tsx new file mode 100644 index 00000000000..a1e4838a861 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-call-expression@loader.tsx @@ -0,0 +1,11 @@ +// Call expression initializers - should still work +const collection = { + create: (name: string) => ({ + name, + items: [] + }) +}.create('todos'); +const SplitLoader = async () => { + return collection.items; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-destructuring.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-destructuring.tsx new file mode 100644 index 00000000000..c413e931518 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-destructuring.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-destructuring.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-destructuring.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Destructuring - ensure we promote the right binding + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-destructuring@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-destructuring@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..b7ed1ffde9b --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-destructuring@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,13 @@ +// Destructuring - ensure we promote the right binding +const cfg = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const { + apiUrl +} = cfg; +function TestComponent() { + // Also uses the destructured binding + return
API: {apiUrl}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-destructuring@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-destructuring@loader.tsx new file mode 100644 index 00000000000..6c138455e6b --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-destructuring@loader.tsx @@ -0,0 +1,13 @@ +// Destructuring - ensure we promote the right binding +const cfg = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const { + apiUrl +} = cfg; +const SplitLoader = async () => { + // Uses the destructured binding + return fetch(apiUrl).then(r => r.json()); +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment.tsx new file mode 100644 index 00000000000..26b129830ff --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment.tsx @@ -0,0 +1,18 @@ +const $$splitComponentImporter = () => import('shared-let-reassignment.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-let-reassignment.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..cd88b5634c8 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,12 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +function TestComponent() { + return
Count: {store.count}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment@component.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment@component.tsx new file mode 100644 index 00000000000..f397a814ed8 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment@component.tsx @@ -0,0 +1,12 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +function TestComponent() { + return
Count: {store.count}
; +} +export { TestComponent as component }; diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment@loader.tsx new file mode 100644 index 00000000000..89f2fced8d8 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-let-reassignment@loader.tsx @@ -0,0 +1,15 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +const SplitLoader = async () => { + store.count++; + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-module-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-module-variable.tsx new file mode 100644 index 00000000000..8cbad6d746c --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-module-variable.tsx @@ -0,0 +1,19 @@ +const $$splitComponentImporter = () => import('shared-module-variable.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-module-variable.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +export const Route = createFileRoute('/todos')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-module-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-module-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..f53fff41701 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-module-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,14 @@ +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +function TodosComponent() { + // Use collection in component + return
{collection.name}
; +} +export { TodosComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-module-variable@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-module-variable@loader.tsx new file mode 100644 index 00000000000..1d52dc1b192 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-module-variable@loader.tsx @@ -0,0 +1,17 @@ +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +const SplitLoader = async () => { + // Use collection in loader + await collection.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-declarations.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-declarations.tsx new file mode 100644 index 00000000000..c299ba8e343 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-declarations.tsx @@ -0,0 +1,13 @@ +const $$splitComponentImporter = () => import('shared-multiple-declarations.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-multiple-declarations.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-declarations@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-declarations@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..c103abe982e --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-declarations@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,14 @@ +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +const collection1 = { + name: 'todos' + }, + collection2 = { + name: 'users' + }; +function TestComponent() { + return
+ {collection1.name} {collection2.name} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-declarations@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-declarations@loader.tsx new file mode 100644 index 00000000000..ffa805a6f6e --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-declarations@loader.tsx @@ -0,0 +1,9 @@ +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +const collection1 = { + name: 'todos' +}; +const SplitLoader = async () => { + return collection1.name; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-variables.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-variables.tsx new file mode 100644 index 00000000000..9ad7427d74a --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-variables.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-multiple-variables.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-multiple-variables.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Multiple shared variables used by both loader and component + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-variables@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-variables@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..6bd0c027294 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-variables@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,18 @@ +// Multiple shared variables used by both loader and component +const collection1 = { + name: 'todos', + preload: async () => {} +}; +const collection2 = { + name: 'users', + preload: async () => {} +}; +const config = { + apiUrl: 'http://api.com' +}; +function TestComponent() { + return
+ {collection1.name} {collection2.name} {config.apiUrl} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-variables@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-variables@loader.tsx new file mode 100644 index 00000000000..3a65c044151 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-multiple-variables@loader.tsx @@ -0,0 +1,17 @@ +// Multiple shared variables used by both loader and component +const collection1 = { + name: 'todos', + preload: async () => {} +}; +const collection2 = { + name: 'users', + preload: async () => {} +}; +const SplitLoader = async () => { + await collection1.preload(); + await collection2.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-closure.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-closure.tsx new file mode 100644 index 00000000000..2049d57035f --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-closure.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-nested-closure.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-nested-closure.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Nested closure - ensure we track through closures + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-closure@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-closure@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..059366b9fce --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-closure@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,6 @@ +// Nested closure - ensure we track through closures +const cfg = { + api: 'http://api.com' +}; +const Component = () =>
{cfg.api}
; +export { Component as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-closure@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-closure@loader.tsx new file mode 100644 index 00000000000..f1cd7767dbb --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-closure@loader.tsx @@ -0,0 +1,7 @@ +// Nested closure - ensure we track through closures +const cfg = { + api: 'http://api.com' +}; +const makeLoader = () => () => cfg.api; +const SplitLoader = makeLoader(); +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-function-usage.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-function-usage.tsx new file mode 100644 index 00000000000..ee30e8c633e --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-function-usage.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-nested-function-usage.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-nested-function-usage.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Variable used inside nested function + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-function-usage@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-function-usage@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..247601d8ec3 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-function-usage@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,9 @@ +// Variable used inside nested function +const collection = { + name: 'todos', + items: [] +}; +function TestComponent() { + return
{collection.name}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-function-usage@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-function-usage@loader.tsx new file mode 100644 index 00000000000..78b8d0a7e47 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-nested-function-usage@loader.tsx @@ -0,0 +1,9 @@ +// Variable used inside nested function +const collection = { + name: 'todos', + items: [] +}; +function loadData() { + return collection.items; +} +export { loadData as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-object-with-methods.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-object-with-methods.tsx new file mode 100644 index 00000000000..3b9a8008094 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-object-with-methods.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-object-with-methods.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-object-with-methods.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Object contains methods (functions) - should still be shared as whole object + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-object-with-methods@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-object-with-methods@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..0b87b4d5576 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-object-with-methods@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,14 @@ +// Object contains methods (functions) - should still be shared as whole object +const api = { + endpoint: 'http://api.com', + fetch: async () => ({ + data: 'loaded' + }), + cache: new Map() +}; +function TestComponent() { + return
+ {api.endpoint} - Cache size: {api.cache.size} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-object-with-methods@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-object-with-methods@loader.tsx new file mode 100644 index 00000000000..53f950387de --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-object-with-methods@loader.tsx @@ -0,0 +1,12 @@ +// Object contains methods (functions) - should still be shared as whole object +const api = { + endpoint: 'http://api.com', + fetch: async () => ({ + data: 'loaded' + }), + cache: new Map() +}; +const SplitLoader = async () => { + return api.fetch(); +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-partial-declarators.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-partial-declarators.tsx new file mode 100644 index 00000000000..5c2291e93af --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-partial-declarators.tsx @@ -0,0 +1,14 @@ +const $$splitComponentImporter = () => import('shared-partial-declarators.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-partial-declarators.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-partial-declarators@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-partial-declarators@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..a6005a94bb0 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-partial-declarators@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,10 @@ +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +const a = 1, + shared = new Map(); +function TestComponent() { + // Uses both shared and a + return
Count: {shared.size + a}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-partial-declarators@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-partial-declarators@loader.tsx new file mode 100644 index 00000000000..3a13615d89c --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-partial-declarators@loader.tsx @@ -0,0 +1,12 @@ +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +const shared = new Map(); +const SplitLoader = async () => { + // Only uses shared, not a + shared.set('loaded', true); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-variable-dependency.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-variable-dependency.tsx new file mode 100644 index 00000000000..58f7df01677 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-variable-dependency.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-variable-dependency.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-variable-dependency.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Variable references another shared variable + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-variable-dependency@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-variable-dependency@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..fe734a45d03 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-variable-dependency@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,15 @@ +// Variable references another shared variable +const baseConfig = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const collection = { + config: baseConfig, + name: 'todos' +}; +function TestComponent() { + return
+ {collection.name} - {baseConfig.apiUrl} +
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-variable-dependency@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-variable-dependency@loader.tsx new file mode 100644 index 00000000000..742f37595ce --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/shared-variable-dependency@loader.tsx @@ -0,0 +1,13 @@ +// Variable references another shared variable +const baseConfig = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const collection = { + config: baseConfig, + name: 'todos' +}; +const SplitLoader = async () => { + return collection.name; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/split-only-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/split-only-variable.tsx new file mode 100644 index 00000000000..f868d5202d2 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/split-only-variable.tsx @@ -0,0 +1,14 @@ +const $$splitComponentImporter = () => import('split-only-variable.tsx?tsr-split=component---errorComponent---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('split-only-variable.tsx?tsr-split=loader'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/split-only-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/split-only-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..761bb11e737 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/split-only-variable@component---errorComponent---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,9 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +function TestComponent() { + // Only component uses onlySplit + return
Size: {onlySplit.size}
; +} +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/split-only-variable@loader.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/split-only-variable@loader.tsx new file mode 100644 index 00000000000..90e112ef6a2 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/2-components-combined-loader-separate/split-only-variable@loader.tsx @@ -0,0 +1,11 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +const SplitLoader = async () => { + // Loader doesn't use onlySplit at all + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-alias-chain.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-alias-chain.tsx new file mode 100644 index 00000000000..d1c9f595610 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-alias-chain.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-alias-chain.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-alias-chain.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Alias chain - ensure we track through aliases + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-alias-chain@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-alias-chain@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..24a3a8ad678 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-alias-chain@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,14 @@ +// Alias chain - ensure we track through aliases +const base = { + name: 'collection', + items: [] +}; +const alias = base; +function TestComponent() { + return
{alias.name}
; +} +const SplitLoader = async () => { + return alias.items; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-alias-chain@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-alias-chain@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-already-exported.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-already-exported.tsx new file mode 100644 index 00000000000..e4858faea09 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-already-exported.tsx @@ -0,0 +1,15 @@ +const $$splitComponentImporter = () => import('shared-already-exported.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-already-exported.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Already exported variable - should not be double-exported +export const collection = { + name: 'todos', + preload: async () => {} +}; +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-already-exported@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-already-exported@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..cdc0d4c02e0 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-already-exported@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,13 @@ +// Already exported variable - should not be double-exported +import { collection } from "shared-already-exported.tsx"; +function TestComponent() { + return
{collection.name}
; +} +const SplitLoader = async () => { + await collection.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-already-exported@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-already-exported@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-call-expression.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-call-expression.tsx new file mode 100644 index 00000000000..20c462bfc71 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-call-expression.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-call-expression.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-call-expression.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Call expression initializers - should still work + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-call-expression@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-call-expression@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..d2ddb0ff86f --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-call-expression@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,23 @@ +// Call expression initializers - should still work +const collection = { + create: (name: string) => ({ + name, + items: [] + }) +}.create('todos'); +const query = { + from: (table: string) => ({ + table, + filters: [] + }) +}.from('users'); +function TestComponent() { + return
+ {collection.name} - {query.table} +
; +} +const SplitLoader = async () => { + return collection.items; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-call-expression@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-call-expression@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-destructuring.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-destructuring.tsx new file mode 100644 index 00000000000..6720ba89156 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-destructuring.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-destructuring.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-destructuring.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Destructuring - ensure we promote the right binding + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-destructuring@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-destructuring@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..03625751b13 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-destructuring@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,18 @@ +// Destructuring - ensure we promote the right binding +const cfg = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const { + apiUrl +} = cfg; +function TestComponent() { + // Also uses the destructured binding + return
API: {apiUrl}
; +} +const SplitLoader = async () => { + // Uses the destructured binding + return fetch(apiUrl).then(r => r.json()); +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-destructuring@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-destructuring@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-let-reassignment.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-let-reassignment.tsx new file mode 100644 index 00000000000..e9d3ebdfb62 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-let-reassignment.tsx @@ -0,0 +1,18 @@ +const $$splitComponentImporter = () => import('shared-let-reassignment.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-let-reassignment.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-let-reassignment@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-let-reassignment@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..ba7c72d7121 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-let-reassignment@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,19 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; +function TestComponent() { + return
Count: {store.count}
; +} +const SplitLoader = async () => { + store.count++; + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-let-reassignment@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-let-reassignment@errorComponent.tsx new file mode 100644 index 00000000000..f52dfd0d532 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-let-reassignment@errorComponent.tsx @@ -0,0 +1,8 @@ +// let with reassignment - tests live binding behavior +let store = { + count: 0 +}; +store = { + count: 1, + updated: true +}; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-module-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-module-variable.tsx new file mode 100644 index 00000000000..437c41a3084 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-module-variable.tsx @@ -0,0 +1,19 @@ +const $$splitComponentImporter = () => import('shared-module-variable.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-module-variable.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +export const Route = createFileRoute('/todos')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-module-variable@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-module-variable@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..4b28c46a7b0 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-module-variable@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,22 @@ +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); +function TodosComponent() { + // Use collection in component + return
{collection.name}
; +} +const SplitLoader = async () => { + // Use collection in loader + await collection.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TodosComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-module-variable@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-module-variable@errorComponent.tsx new file mode 100644 index 00000000000..caf87ba5c8d --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-module-variable@errorComponent.tsx @@ -0,0 +1,9 @@ +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { + name: 'todos', + preload: async () => {} +}; + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-declarations.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-declarations.tsx new file mode 100644 index 00000000000..278c8e95812 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-declarations.tsx @@ -0,0 +1,13 @@ +const $$splitComponentImporter = () => import('shared-multiple-declarations.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-multiple-declarations.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-declarations@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-declarations@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..dbc75a6caf9 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-declarations@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,18 @@ +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +const collection1 = { + name: 'todos' + }, + collection2 = { + name: 'users' + }; +function TestComponent() { + return
+ {collection1.name} {collection2.name} +
; +} +const SplitLoader = async () => { + return collection1.name; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-declarations@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-declarations@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-variables.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-variables.tsx new file mode 100644 index 00000000000..d71a7a0169d --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-variables.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-multiple-variables.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-multiple-variables.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Multiple shared variables used by both loader and component + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-variables@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-variables@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..9c780d4347d --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-variables@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,26 @@ +// Multiple shared variables used by both loader and component +const collection1 = { + name: 'todos', + preload: async () => {} +}; +const collection2 = { + name: 'users', + preload: async () => {} +}; +const config = { + apiUrl: 'http://api.com' +}; +function TestComponent() { + return
+ {collection1.name} {collection2.name} {config.apiUrl} +
; +} +const SplitLoader = async () => { + await collection1.preload(); + await collection2.preload(); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-variables@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-multiple-variables@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-closure.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-closure.tsx new file mode 100644 index 00000000000..c29dc853fdf --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-closure.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-nested-closure.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-nested-closure.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Nested closure - ensure we track through closures + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-closure@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-closure@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..dc28c14a14a --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-closure@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,9 @@ +// Nested closure - ensure we track through closures +const cfg = { + api: 'http://api.com' +}; +const makeLoader = () => () => cfg.api; +const Component = () =>
{cfg.api}
; +const SplitLoader = makeLoader(); +export { SplitLoader as loader }; +export { Component as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-closure@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-closure@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-function-usage.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-function-usage.tsx new file mode 100644 index 00000000000..13b175e04ec --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-function-usage.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-nested-function-usage.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-nested-function-usage.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Variable used inside nested function + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-function-usage@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-function-usage@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..720598b13bd --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-function-usage@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,13 @@ +// Variable used inside nested function +const collection = { + name: 'todos', + items: [] +}; +function loadData() { + return collection.items; +} +function TestComponent() { + return
{collection.name}
; +} +export { loadData as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-function-usage@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-nested-function-usage@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-object-with-methods.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-object-with-methods.tsx new file mode 100644 index 00000000000..3892ef14436 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-object-with-methods.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-object-with-methods.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-object-with-methods.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Object contains methods (functions) - should still be shared as whole object + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-object-with-methods@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-object-with-methods@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..7ee457ba36d --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-object-with-methods@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,18 @@ +// Object contains methods (functions) - should still be shared as whole object +const api = { + endpoint: 'http://api.com', + fetch: async () => ({ + data: 'loaded' + }), + cache: new Map() +}; +function TestComponent() { + return
+ {api.endpoint} - Cache size: {api.cache.size} +
; +} +const SplitLoader = async () => { + return api.fetch(); +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-object-with-methods@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-object-with-methods@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-partial-declarators.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-partial-declarators.tsx new file mode 100644 index 00000000000..0d68de7cb30 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-partial-declarators.tsx @@ -0,0 +1,14 @@ +const $$splitComponentImporter = () => import('shared-partial-declarators.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-partial-declarators.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-partial-declarators@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-partial-declarators@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..2fe8995815d --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-partial-declarators@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,18 @@ +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +const a = 1, + shared = new Map(); +function TestComponent() { + // Uses both shared and a + return
Count: {shared.size + a}
; +} +const SplitLoader = async () => { + // Only uses shared, not a + shared.set('loaded', true); + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-partial-declarators@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-partial-declarators@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-variable-dependency.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-variable-dependency.tsx new file mode 100644 index 00000000000..fe9f631e2fc --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-variable-dependency.tsx @@ -0,0 +1,12 @@ +const $$splitComponentImporter = () => import('shared-variable-dependency.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('shared-variable-dependency.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Variable references another shared variable + +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-variable-dependency@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-variable-dependency@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..eec1a99efa2 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-variable-dependency@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,19 @@ +// Variable references another shared variable +const baseConfig = { + apiUrl: 'http://api.com', + timeout: 5000 +}; +const collection = { + config: baseConfig, + name: 'todos' +}; +function TestComponent() { + return
+ {collection.name} - {baseConfig.apiUrl} +
; +} +const SplitLoader = async () => { + return collection.name; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-variable-dependency@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/shared-variable-dependency@errorComponent.tsx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/split-only-variable.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/split-only-variable.tsx new file mode 100644 index 00000000000..56d47b70fd2 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/split-only-variable.tsx @@ -0,0 +1,14 @@ +const $$splitComponentImporter = () => import('split-only-variable.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyRouteComponent } from '@tanstack/solid-router'; +const $$splitLoaderImporter = () => import('split-only-variable.tsx?tsr-split=component---loader---notFoundComponent---pendingComponent'); +import { lazyFn } from '@tanstack/solid-router'; +import { createFileRoute } from '@tanstack/solid-router'; + +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +export const Route = createFileRoute('/test')({ + loader: lazyFn($$splitLoaderImporter, 'loader'), + component: lazyRouteComponent($$splitComponentImporter, 'component') +}); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/split-only-variable@component---loader---notFoundComponent---pendingComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/split-only-variable@component---loader---notFoundComponent---pendingComponent.tsx new file mode 100644 index 00000000000..65dfd7c5ca0 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/split-only-variable@component---loader---notFoundComponent---pendingComponent.tsx @@ -0,0 +1,16 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); +function TestComponent() { + // Only component uses onlySplit + return
Size: {onlySplit.size}
; +} +const SplitLoader = async () => { + // Loader doesn't use onlySplit at all + return { + data: 'loaded' + }; +}; +export { SplitLoader as loader }; +export { TestComponent as component }; \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/split-only-variable@errorComponent.tsx b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/split-only-variable@errorComponent.tsx new file mode 100644 index 00000000000..90e58d835af --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/snapshots/solid/3-all-combined-errorComponent-separate/split-only-variable@errorComponent.tsx @@ -0,0 +1,4 @@ +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map(); +onlySplit.set('key', 'value'); \ No newline at end of file diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-alias-chain.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-alias-chain.tsx new file mode 100644 index 00000000000..bb80c4c956a --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-alias-chain.tsx @@ -0,0 +1,16 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Alias chain - ensure we track through aliases +const base = { name: 'collection', items: [] } +const alias = base + +export const Route = createFileRoute('/test')({ + loader: async () => { + return alias.items + }, + component: TestComponent, +}) + +function TestComponent() { + return
{alias.name}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-already-exported.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-already-exported.tsx new file mode 100644 index 00000000000..419e56fa15f --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-already-exported.tsx @@ -0,0 +1,16 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Already exported variable - should not be double-exported +export const collection = { name: 'todos', preload: async () => {} } + +export const Route = createFileRoute('/test')({ + loader: async () => { + await collection.preload() + return { data: 'loaded' } + }, + component: TestComponent, +}) + +function TestComponent() { + return
{collection.name}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-call-expression.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-call-expression.tsx new file mode 100644 index 00000000000..50df00bd8a1 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-call-expression.tsx @@ -0,0 +1,24 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Call expression initializers - should still work +const collection = { create: (name: string) => ({ name, items: [] }) }.create( + 'todos', +) +const query = { from: (table: string) => ({ table, filters: [] }) }.from( + 'users', +) + +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection.items + }, + component: TestComponent, +}) + +function TestComponent() { + return ( +
+ {collection.name} - {query.table} +
+ ) +} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-destructuring.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-destructuring.tsx new file mode 100644 index 00000000000..c702e852386 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-destructuring.tsx @@ -0,0 +1,18 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Destructuring - ensure we promote the right binding +const cfg = { apiUrl: 'http://api.com', timeout: 5000 } +const { apiUrl } = cfg + +export const Route = createFileRoute('/test')({ + loader: async () => { + // Uses the destructured binding + return fetch(apiUrl).then((r) => r.json()) + }, + component: TestComponent, +}) + +function TestComponent() { + // Also uses the destructured binding + return
API: {apiUrl}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-let-reassignment.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-let-reassignment.tsx new file mode 100644 index 00000000000..30e6b3947f2 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-let-reassignment.tsx @@ -0,0 +1,17 @@ +import { createFileRoute } from '@tanstack/react-router' + +// let with reassignment - tests live binding behavior +let store = { count: 0 } +store = { count: 1, updated: true } + +export const Route = createFileRoute('/test')({ + loader: async () => { + store.count++ + return { data: 'loaded' } + }, + component: TestComponent, +}) + +function TestComponent() { + return
Count: {store.count}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-module-variable.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-module-variable.tsx new file mode 100644 index 00000000000..64ce29cd56f --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-module-variable.tsx @@ -0,0 +1,22 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { name: 'todos', preload: async () => {} } + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name) + +export const Route = createFileRoute('/todos')({ + loader: async () => { + // Use collection in loader + await collection.preload() + return { data: 'loaded' } + }, + component: TodosComponent, +}) + +function TodosComponent() { + // Use collection in component + return
{collection.name}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-multiple-declarations.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-multiple-declarations.tsx new file mode 100644 index 00000000000..bffe8459c4f --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-multiple-declarations.tsx @@ -0,0 +1,21 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +const collection1 = { name: 'todos' }, + collection2 = { name: 'users' } + +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection1.name + }, + component: TestComponent, +}) + +function TestComponent() { + return ( +
+ {collection1.name} {collection2.name} +
+ ) +} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-multiple-variables.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-multiple-variables.tsx new file mode 100644 index 00000000000..0abae8e5dde --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-multiple-variables.tsx @@ -0,0 +1,23 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Multiple shared variables used by both loader and component +const collection1 = { name: 'todos', preload: async () => {} } +const collection2 = { name: 'users', preload: async () => {} } +const config = { apiUrl: 'http://api.com' } + +export const Route = createFileRoute('/test')({ + loader: async () => { + await collection1.preload() + await collection2.preload() + return { data: 'loaded' } + }, + component: TestComponent, +}) + +function TestComponent() { + return ( +
+ {collection1.name} {collection2.name} {config.apiUrl} +
+ ) +} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-nested-closure.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-nested-closure.tsx new file mode 100644 index 00000000000..49006293230 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-nested-closure.tsx @@ -0,0 +1,11 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Nested closure - ensure we track through closures +const cfg = { api: 'http://api.com' } +const makeLoader = () => () => cfg.api +const Component = () =>
{cfg.api}
+ +export const Route = createFileRoute('/test')({ + loader: makeLoader(), + component: Component, +}) diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-nested-function-usage.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-nested-function-usage.tsx new file mode 100644 index 00000000000..bff2daa131c --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-nested-function-usage.tsx @@ -0,0 +1,17 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Variable used inside nested function +const collection = { name: 'todos', items: [] } + +function loadData() { + return collection.items +} + +export const Route = createFileRoute('/test')({ + loader: loadData, + component: TestComponent, +}) + +function TestComponent() { + return
{collection.name}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-object-with-methods.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-object-with-methods.tsx new file mode 100644 index 00000000000..72cf0ee2c68 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-object-with-methods.tsx @@ -0,0 +1,23 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Object contains methods (functions) - should still be shared as whole object +const api = { + endpoint: 'http://api.com', + fetch: async () => ({ data: 'loaded' }), + cache: new Map(), +} + +export const Route = createFileRoute('/test')({ + loader: async () => { + return api.fetch() + }, + component: TestComponent, +}) + +function TestComponent() { + return ( +
+ {api.endpoint} - Cache size: {api.cache.size} +
+ ) +} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-partial-declarators.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-partial-declarators.tsx new file mode 100644 index 00000000000..4097c74cf03 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-partial-declarators.tsx @@ -0,0 +1,21 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +const a = 1, + shared = new Map() + +export const Route = createFileRoute('/test')({ + loader: async () => { + // Only uses shared, not a + shared.set('loaded', true) + return { data: 'loaded' } + }, + component: TestComponent, +}) + +function TestComponent() { + // Uses both shared and a + return
Count: {shared.size + a}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/shared-variable-dependency.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/shared-variable-dependency.tsx new file mode 100644 index 00000000000..45f814772ca --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/shared-variable-dependency.tsx @@ -0,0 +1,20 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Variable references another shared variable +const baseConfig = { apiUrl: 'http://api.com', timeout: 5000 } +const collection = { config: baseConfig, name: 'todos' } + +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection.name + }, + component: TestComponent, +}) + +function TestComponent() { + return ( +
+ {collection.name} - {baseConfig.apiUrl} +
+ ) +} diff --git a/packages/router-plugin/tests/code-splitter/test-files/react/split-only-variable.tsx b/packages/router-plugin/tests/code-splitter/test-files/react/split-only-variable.tsx new file mode 100644 index 00000000000..6cd1474c136 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/react/split-only-variable.tsx @@ -0,0 +1,19 @@ +import { createFileRoute } from '@tanstack/react-router' + +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map() +onlySplit.set('key', 'value') + +export const Route = createFileRoute('/test')({ + loader: async () => { + // Loader doesn't use onlySplit at all + return { data: 'loaded' } + }, + component: TestComponent, +}) + +function TestComponent() { + // Only component uses onlySplit + return
Size: {onlySplit.size}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-alias-chain.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-alias-chain.tsx new file mode 100644 index 00000000000..08aa78def0e --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-alias-chain.tsx @@ -0,0 +1,16 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Alias chain - ensure we track through aliases +const base = { name: 'collection', items: [] } +const alias = base + +export const Route = createFileRoute('/test')({ + loader: async () => { + return alias.items + }, + component: TestComponent, +}) + +function TestComponent() { + return
{alias.name}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-already-exported.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-already-exported.tsx new file mode 100644 index 00000000000..7ce92d13854 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-already-exported.tsx @@ -0,0 +1,16 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Already exported variable - should not be double-exported +export const collection = { name: 'todos', preload: async () => {} } + +export const Route = createFileRoute('/test')({ + loader: async () => { + await collection.preload() + return { data: 'loaded' } + }, + component: TestComponent, +}) + +function TestComponent() { + return
{collection.name}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-call-expression.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-call-expression.tsx new file mode 100644 index 00000000000..3f25b585e35 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-call-expression.tsx @@ -0,0 +1,24 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Call expression initializers - should still work +const collection = { create: (name: string) => ({ name, items: [] }) }.create( + 'todos', +) +const query = { from: (table: string) => ({ table, filters: [] }) }.from( + 'users', +) + +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection.items + }, + component: TestComponent, +}) + +function TestComponent() { + return ( +
+ {collection.name} - {query.table} +
+ ) +} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-destructuring.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-destructuring.tsx new file mode 100644 index 00000000000..6132b7d0a91 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-destructuring.tsx @@ -0,0 +1,18 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Destructuring - ensure we promote the right binding +const cfg = { apiUrl: 'http://api.com', timeout: 5000 } +const { apiUrl } = cfg + +export const Route = createFileRoute('/test')({ + loader: async () => { + // Uses the destructured binding + return fetch(apiUrl).then((r) => r.json()) + }, + component: TestComponent, +}) + +function TestComponent() { + // Also uses the destructured binding + return
API: {apiUrl}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-let-reassignment.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-let-reassignment.tsx new file mode 100644 index 00000000000..9503124dbff --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-let-reassignment.tsx @@ -0,0 +1,17 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// let with reassignment - tests live binding behavior +let store = { count: 0 } +store = { count: 1, updated: true } + +export const Route = createFileRoute('/test')({ + loader: async () => { + store.count++ + return { data: 'loaded' } + }, + component: TestComponent, +}) + +function TestComponent() { + return
Count: {store.count}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-module-variable.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-module-variable.tsx new file mode 100644 index 00000000000..f5b26348221 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-module-variable.tsx @@ -0,0 +1,22 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Module-level variable used in both loader and component +// This simulates a collection/query that should only be initialized once +const collection = { name: 'todos', preload: async () => {} } + +// Side effect at module level - should only run once +console.log('Module initialized:', collection.name) + +export const Route = createFileRoute('/todos')({ + loader: async () => { + // Use collection in loader + await collection.preload() + return { data: 'loaded' } + }, + component: TodosComponent, +}) + +function TodosComponent() { + // Use collection in component + return
{collection.name}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-multiple-declarations.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-multiple-declarations.tsx new file mode 100644 index 00000000000..3dda89d04f8 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-multiple-declarations.tsx @@ -0,0 +1,21 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Multiple declarations in same const statement +// Only collection1 is shared, but both are in same declaration +const collection1 = { name: 'todos' }, + collection2 = { name: 'users' } + +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection1.name + }, + component: TestComponent, +}) + +function TestComponent() { + return ( +
+ {collection1.name} {collection2.name} +
+ ) +} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-multiple-variables.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-multiple-variables.tsx new file mode 100644 index 00000000000..bb6fe1bc707 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-multiple-variables.tsx @@ -0,0 +1,23 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Multiple shared variables used by both loader and component +const collection1 = { name: 'todos', preload: async () => {} } +const collection2 = { name: 'users', preload: async () => {} } +const config = { apiUrl: 'http://api.com' } + +export const Route = createFileRoute('/test')({ + loader: async () => { + await collection1.preload() + await collection2.preload() + return { data: 'loaded' } + }, + component: TestComponent, +}) + +function TestComponent() { + return ( +
+ {collection1.name} {collection2.name} {config.apiUrl} +
+ ) +} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-nested-closure.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-nested-closure.tsx new file mode 100644 index 00000000000..c2163f15311 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-nested-closure.tsx @@ -0,0 +1,11 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Nested closure - ensure we track through closures +const cfg = { api: 'http://api.com' } +const makeLoader = () => () => cfg.api +const Component = () =>
{cfg.api}
+ +export const Route = createFileRoute('/test')({ + loader: makeLoader(), + component: Component, +}) diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-nested-function-usage.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-nested-function-usage.tsx new file mode 100644 index 00000000000..b35d6d89265 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-nested-function-usage.tsx @@ -0,0 +1,17 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Variable used inside nested function +const collection = { name: 'todos', items: [] } + +function loadData() { + return collection.items +} + +export const Route = createFileRoute('/test')({ + loader: loadData, + component: TestComponent, +}) + +function TestComponent() { + return
{collection.name}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-object-with-methods.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-object-with-methods.tsx new file mode 100644 index 00000000000..4ff7442ba42 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-object-with-methods.tsx @@ -0,0 +1,23 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Object contains methods (functions) - should still be shared as whole object +const api = { + endpoint: 'http://api.com', + fetch: async () => ({ data: 'loaded' }), + cache: new Map(), +} + +export const Route = createFileRoute('/test')({ + loader: async () => { + return api.fetch() + }, + component: TestComponent, +}) + +function TestComponent() { + return ( +
+ {api.endpoint} - Cache size: {api.cache.size} +
+ ) +} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-partial-declarators.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-partial-declarators.tsx new file mode 100644 index 00000000000..5cea23681f2 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-partial-declarators.tsx @@ -0,0 +1,21 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Multiple declarators in same statement +// Only 'shared' is used by both loader and component +// 'a' is only used in component, should NOT be exported +const a = 1, + shared = new Map() + +export const Route = createFileRoute('/test')({ + loader: async () => { + // Only uses shared, not a + shared.set('loaded', true) + return { data: 'loaded' } + }, + component: TestComponent, +}) + +function TestComponent() { + // Uses both shared and a + return
Count: {shared.size + a}
+} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/shared-variable-dependency.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-variable-dependency.tsx new file mode 100644 index 00000000000..d825c081ffa --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/shared-variable-dependency.tsx @@ -0,0 +1,20 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Variable references another shared variable +const baseConfig = { apiUrl: 'http://api.com', timeout: 5000 } +const collection = { config: baseConfig, name: 'todos' } + +export const Route = createFileRoute('/test')({ + loader: async () => { + return collection.name + }, + component: TestComponent, +}) + +function TestComponent() { + return ( +
+ {collection.name} - {baseConfig.apiUrl} +
+ ) +} diff --git a/packages/router-plugin/tests/code-splitter/test-files/solid/split-only-variable.tsx b/packages/router-plugin/tests/code-splitter/test-files/solid/split-only-variable.tsx new file mode 100644 index 00000000000..f98daf9f5c4 --- /dev/null +++ b/packages/router-plugin/tests/code-splitter/test-files/solid/split-only-variable.tsx @@ -0,0 +1,19 @@ +import { createFileRoute } from '@tanstack/solid-router' + +// Variable used ONLY in component (split part), NOT in loader +// Should NOT be exported from reference file or imported in split file +const onlySplit = new Map() +onlySplit.set('key', 'value') + +export const Route = createFileRoute('/test')({ + loader: async () => { + // Loader doesn't use onlySplit at all + return { data: 'loaded' } + }, + component: TestComponent, +}) + +function TestComponent() { + // Only component uses onlySplit + return
Size: {onlySplit.size}
+}