Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/router-plugin/src/core/code-splitter/compilers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ export function compileCodeSplitReferenceRoute(
return
}

// Exit early if the value is undefined
// Since we don't need to run an import just to get the value of `undefined`
// This is useful for cases like: `createFileRoute('/')({ component: undefined })`
if (
t.isIdentifier(prop.value) &&
prop.value.name === 'undefined'
) {
return
}

const splitNodeMeta = SPLIT_NODES_CONFIG.get(key as any)!

// We need to extract the existing search params from the filename, if any
Expand Down Expand Up @@ -253,7 +263,6 @@ export function compileCodeSplitReferenceRoute(
// Prepend the import statement to the program along with the importer function
// Check to see if lazyRouteComponent is already imported before attempting
// to import it again

if (
!hasImportedOrDefinedIdentifier(
LAZY_ROUTE_COMPONENT_IDENT,
Expand Down Expand Up @@ -461,6 +470,14 @@ export function compileCodeSplitVirtualRoute(

const value = prop.value

// If the value for the `key` is `undefined`, then we don't need to include it
// in the split file, so we can just return, since it will kept in-place in the
// reference file
// This is useful for cases like: `createFileRoute('/')({ component: undefined })`
if (t.isIdentifier(value) && value.name === 'undefined') {
return
}

let isExported = false
if (t.isIdentifier(value)) {
isExported = hasExport(ast, value)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/')({
component: undefined
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
2 changes: 2 additions & 0 deletions .../snapshots/react/1-default/development/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/')({
component: undefined
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
2 changes: 2 additions & 0 deletions ...r/snapshots/react/1-default/production/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/')({
component: undefined
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/')({
component: undefined
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/')({
component: undefined
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/')({
component: undefined
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from 'react';
import { Route } from "explicit-undefined-component.tsx";
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/')({
component: undefined,
})