Skip to content
Source
Sign inSign up
TanStack/router

fix(router-plugin): split object-form loaders #8755

Openshkumbinhasani(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/8755/headopened

Showing 48 changed files with 143 additions and 24 deletions (loading 45).

x
0 of 48 viewed, 48 left
5 additions and 0 deletions.changeset/split-object-form-loader.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/router-plugin': patch
+---
+​
+Split only the `handler` of a loader in object form (`loader: { handler, staleReloadMode }`) when `loader` is code-split, and keep its other options on the route. Before, the split chunk failed with `Unexpected splitNode type ☝️: ObjectExpression`.
137 additions and 23 deletionspackages/router-plugin/src/core/code-splitter/compilers.tsModified
View file
@@ -140,6 +140,88 @@
​
/**
+ * A loader can be an object, `{ handler, staleReloadMode }`. The router reads
+ * its other keys from the route options, so only `handler` is split. Returns
+ * the property to split, or `undefined` to keep the whole loader in the route
+ * file. A `handler() {}` method is replaced by a property holding the same
+ * function, so it splits like any other value.
+ */
+function getLoaderHandler(
+ loader: t.ObjectExpression,
+): t.ObjectProperty | undefined {
+ // The last `handler` wins, unless a spread or computed key after it may
+ // replace it
+ for (let index = loader.properties.length - 1; index >= 0; index--) {
+ const prop = loader.properties[index]!