Skip to content

Commit 64aebef

Browse files
committed
feat(tanstack-router)!: Solid 2 support (0.2.0)
The Solid flavor now targets Solid 2 only: solid-js 2.x, @solidjs/web 2.x, @nativescript-community/solid-js 2.x and @tanstack/solid-router 2.x. - solid-web-shim.js stands in for @solidjs/web, binding the router's renderer helpers to the NativeScript universal renderer; template() throws a clear error pointing at defaultErrorComponent / defaultNotFoundComponent. - Library sources are plain .ts using createComponent (no JSX runtime shim). - Provider/PageRenderer/Link follow Solid 2 rules: Errored, onSettled, two-arg effects, loads and Frame navigation outside owned scopes, an explicit startTransition hook. - nativescript.vite.mjs only provides the @solidjs/web alias; apps register the TanStack router plugin in their own Vite config. - Modal routers no longer replace the app router on globalThis.__ns_router. - scrollTo is stubbed for router-core's post-render scroll reset. - Shared .d.ts chunks are included in the published files.
1 parent eb0fb3f commit 64aebef

35 files changed

Lines changed: 2176 additions & 2667 deletions

‎package-lock.json‎

Lines changed: 129 additions & 211 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,35 @@
3434
"@babel/core": "^7.24.4",
3535
"@babel/preset-env": "^7.24.4",
3636
"@babel/preset-typescript": "^7.23.3",
37-
"@nativescript-community/solid-js": "^0.1.2",
37+
"@nativescript-community/react": "^19.0.0",
38+
"@nativescript-community/solid-js": "^2.0.1",
3839
"@nativescript-dom/core-types": "1.0.32",
3940
"@nativescript-dom/solidjs-types": "1.0.25",
4041
"@nativescript/angular": "^19.0.0",
41-
"@nativescript/core": "~9.0.0",
42+
"@nativescript/core": "~9.1.4",
4243
"@nativescript/plugin-tools": "5.5.3",
4344
"@nativescript/tailwind": "~2.1.0",
4445
"@nativescript/types": "~9.0.0",
4546
"@nativescript/webpack": "~5.0.31",
4647
"@ngtools/webpack": "^19.0.0",
47-
"@tanstack/history": "^1.161.6",
48-
"@tanstack/router-core": "^1.169.1",
49-
"@tanstack/solid-router": "^1.169.1",
50-
"@tanstack/react-router": "^1.169.1",
48+
"@solidjs/universal": "^2.0.3",
49+
"@solidjs/web": "^2.0.3",
50+
"@tanstack/history": "1.162.5",
51+
"@tanstack/react-router": "^1.170.46",
52+
"@tanstack/router-core": "1.171.39",
53+
"@tanstack/solid-router": "2.0.0-rc.12",
5154
"@triniwiz/nativescript-image-cache-it": "^8.0.1",
5255
"@types/react": "^19.0.0",
53-
"react": "^19.0.0",
54-
"react-reconciler": "^0.32.0",
5556
"babel-loader": "^9.1.3",
56-
"babel-preset-solid": "^1.8.19",
5757
"dominative": "^0.1.3",
5858
"husky": "~9.0.0",
5959
"jsdom": "^29.1.1",
6060
"ng-packagr": "^19.0.0",
61+
"react": "^19.0.0",
62+
"react-reconciler": "^0.32.0",
6163
"rxjs": "~7.8.0",
6264
"sass": "1.53.0",
63-
"solid-js": "^1.9.11",
64-
"solid-refresh": "^0.7.5",
65+
"solid-js": "^2.0.3",
6566
"tailwindcss": "~3.4.3",
6667
"tsup": "^8.3.5",
6768
"typescript": "~5.8.0",

‎packages/tanstack-router/CHANGELOG.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
## 0.2.0 (2026-11-23)
2+
3+
### ⚠️ Breaking Changes
4+
5+
- The Solid flavor now targets Solid 2 only: `solid-js` 2.x, `@solidjs/web` 2.x, `@nativescript-community/solid-js` 2.x and `@tanstack/solid-router` 2.x (`>=2.0.0-rc.12`). Solid 1 is no longer supported.
6+
- `NativeScriptRouterProviderProps.actionBar` and `Link`'s `children` are typed with Solid 2's `Element` instead of `JSX.Element`.
7+
- `solid-js-jsx-runtime-shim.js` is no longer shipped; the Solid sources are compiled without JSX.
8+
- `nativescript.vite.mjs` no longer registers the TanStack router plugin, and `@tanstack/router-plugin` is no longer a dependency. Apps using file-based routes add `tanstackRouter({ target: 'solid', autoCodeSplitting: false })` from `@tanstack/router-plugin/vite` to their own Vite config.
9+
10+
### 🚀 Features
11+
12+
- `solid-web-shim.js` now stands in for `@solidjs/web` (aliased by `nativescript.vite.mjs` and `nativescript.webpack.js`), binding the router's renderer helpers (`insert`, `spread`, `effect`, `memo`, `Dynamic`, ...) to the universal renderer of `@nativescript-community/solid-js`.
13+
- React flavor updated to `@tanstack/react-router` 1.170 / `@tanstack/router-core` 1.171.
14+
15+
### 🩹 Fixes
16+
17+
- Pages render under `Errored` and keep their views through the native pop animation while their reactivity is torn down.
18+
- Initial and history-driven loads run outside Solid owners, and Frame navigation runs after (not inside) the navigation effect, as Solid 2 requires.
19+
- Modal routers no longer replace the app router registered on `globalThis.__ns_router`, so HMR keeps patching the live router after a modal opens.
20+
- `scrollTo` is stubbed as a no-op global: router-core resets window scroll after every render and threw `ReferenceError: scrollTo is not defined` on each navigation.
21+
22+
### 🔧 Chores
23+
24+
- Drop solid-refresh proxy unwrapping from the HMR remount path; `@nativescript/vite` patches route components directly.
25+
126
## 0.1.2 (2026-05-03)
227

328
### 🧪 Tests

‎packages/tanstack-router/README.md‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,36 @@ The package is structured to support any framework (`react`, `vue`, `svelte`, `a
1515
## Install
1616

1717
```bash
18-
npm install @nativescript/tanstack-router @tanstack/solid-router @tanstack/history
18+
npm install @nativescript/tanstack-router @tanstack/solid-router@^2.0.0-rc.12 @tanstack/history
1919
```
2020

21-
Peer dependencies expected in the host app:
21+
The Solid flavor targets Solid 2. Peer dependencies expected in the host app:
2222

2323
- `@nativescript/core`
24-
- `@nativescript-community/solid-js`
25-
- `solid-js`
24+
- `@nativescript-community/solid-js` (2.x)
25+
- `solid-js` and `@solidjs/web` (2.x)
26+
27+
`@tanstack/solid-router` takes its renderer helpers from `@solidjs/web`. The package's
28+
`nativescript.vite.mjs` (picked up automatically by `@nativescript/vite`) and
29+
`nativescript.webpack.js` alias `@solidjs/web` to a NativeScript stand-in backed by
30+
`@nativescript-community/solid-js`, so router internals and app JSX share one renderer.
31+
32+
The router's built-in DOM fallbacks (default error / not-found components) cannot render
33+
in NativeScript; supply NativeScript components through `defaultErrorComponent` /
34+
`defaultNotFoundComponent` (or per-route `errorComponent` / `notFoundComponent`) when
35+
you render nested routes through `<Outlet />`.
36+
37+
## File-Based Routes
38+
39+
Register the TanStack router plugin in the app's own Vite config, before the Solid plugin. It reads
40+
`tsr.config.json` and regenerates the route tree:
41+
42+
```ts
43+
import { tanstackRouter } from '@tanstack/router-plugin/vite'
44+
45+
// inside defineConfig(...).plugins
46+
tanstackRouter({ target: 'solid', autoCodeSplitting: false }),
47+
```
2648

2749
## Import Paths
2850

Lines changed: 5 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,13 @@
1-
import { createRequire } from 'node:module';
2-
import { dirname, join } from 'node:path';
3-
import { existsSync } from 'node:fs';
41
import { fileURLToPath } from 'node:url';
5-
import { tanstackRouter } from '@tanstack/router-plugin/vite';
62

7-
const require = createRequire(import.meta.url);
8-
const projectRoot = process.cwd();
9-
10-
let solidJsRuntimePath;
11-
let solidJsHPath;
123
const solidWebShimPath = fileURLToPath(new URL('./solid-web-shim.js', import.meta.url));
13-
const jsxRuntimeShimPath = fileURLToPath(new URL('./solid-js-jsx-runtime-shim.js', import.meta.url));
14-
const tsrConfigPath = join(projectRoot, 'tsr.config.json');
15-
const defaultRoutesDirectory = join(projectRoot, 'src', 'routes');
16-
17-
function hasFileBasedRoutingConfig() {
18-
return existsSync(tsrConfigPath) || existsSync(defaultRoutesDirectory);
19-
}
20-
21-
function forcePreEnforce(plugin) {
22-
if (!plugin || typeof plugin !== 'object') {
23-
return plugin;
24-
}
25-
26-
if (Array.isArray(plugin)) {
27-
return plugin.map(forcePreEnforce);
28-
}
29-
30-
return {
31-
...plugin,
32-
enforce: plugin.enforce ?? 'pre',
33-
};
34-
}
35-
36-
function getRouterPlugins() {
37-
if (!hasFileBasedRoutingConfig()) {
38-
return [];
39-
}
40-
41-
const plugin = tanstackRouter({
42-
// with other frameworks, we can embed different configs
43-
target: 'solid',
44-
autoCodeSplitting: false,
45-
enableRouteGeneration: true,
46-
});
47-
48-
const normalized = forcePreEnforce(plugin);
49-
return Array.isArray(normalized) ? normalized : [normalized];
50-
}
51-
52-
try {
53-
const solidJsPackagePath = require.resolve('solid-js/package.json');
54-
const solidJsRoot = dirname(solidJsPackagePath);
55-
56-
const candidateRuntimePath = join(solidJsRoot, 'h', 'jsx-runtime', 'dist', 'jsx.js');
57-
const candidateHPath = join(solidJsRoot, 'h', 'dist', 'h.js');
58-
59-
if (existsSync(candidateRuntimePath)) {
60-
solidJsRuntimePath = candidateRuntimePath;
61-
}
62-
63-
if (existsSync(candidateHPath)) {
64-
solidJsHPath = candidateHPath;
65-
}
66-
67-
if (!solidJsRuntimePath || !solidJsHPath) {
68-
console.warn(
69-
'[nativescript/tanstack-router] Could not resolve one or more SolidJS runtime alias paths for Vite.',
70-
{
71-
runtimeFound: !!solidJsRuntimePath,
72-
hFound: !!solidJsHPath,
73-
solidJsRoot,
74-
},
75-
);
76-
}
77-
} catch (error) {
78-
console.warn(
79-
'[nativescript/tanstack-router] Failed to resolve SolidJS package location for Vite aliases.',
80-
error instanceof Error ? error.message : error,
81-
);
82-
}
834

845
export default () => ({
85-
plugins: [...getRouterPlugins()],
866
resolve: {
87-
alias: {
88-
// Keep Vite behavior aligned with nativescript.webpack.js integration.
89-
'solid-js/web': solidWebShimPath,
90-
// NOTE: do NOT alias `solid-js/jsx-runtime` / `solid-js/jsx-dev-runtime` to a
91-
// shim file INSIDE this package. @nativescript/vite (solid flavor) already provides
92-
// its own jsx-runtime shim and serves it over HTTP. When this alias pointed at
93-
// `./solid-js-jsx-runtime-shim.js` (a subpath of this vendored runtime plugin), the
94-
// @nativescript/vite device rewriter collapsed that subpath to the vendor-package
95-
// ROOT binding — `jsx = __nsPick("@nativescript/tanstack-router", "jsx")` — and the
96-
// root has no `jsx` export, so `jsx` was `undefined`. Every `jsx(...)` call in the
97-
// bundled router JSX (e.g. renderPage's `<RouterContextProvider><SafeRouteView/>`)
98-
// then threw "jsx is not a function", the route Page never rendered, the Frame stayed
99-
// empty, and the app showed a blank screen under HMR. Letting @nativescript/vite's
100-
// HTTP-served shim resolve these keeps `jsx` a real function. (The webpack path still
101-
// aliases them via nativescript.webpack.js, which has its own shim handling.)
102-
...(solidJsHPath
103-
? {
104-
'solid-js/h': solidJsHPath,
105-
}
106-
: {}),
107-
},
7+
alias: [
8+
// Anchored: `@solidjs/web/*` subpaths (server-functions, storage) are
9+
// renderer-independent and must keep resolving to the real package.
10+
{ find: /^@solidjs\/web$/, replacement: solidWebShimPath },
11+
],
10812
},
10913
});
Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
const path = require('path');
2-
const Webpack = require('webpack');
32

43
/**
54
* @param {typeof import('@nativescript/webpack')} webpack
65
*/
76
module.exports = (webpack) => {
87
webpack.mergeWebpack((config) => {
98
const shimPath = path.resolve(__dirname, 'solid-web-shim.js');
10-
const jsxRuntimeShimPath = path.resolve(__dirname, 'solid-js-jsx-runtime-shim.js');
119

12-
if (!config.resolve) {
13-
config.resolve = {};
14-
}
15-
16-
if (!config.resolve.alias) {
17-
config.resolve.alias = {};
18-
}
19-
20-
config.resolve.alias['solid-js/web$'] = shimPath;
21-
config.resolve.alias['solid-js/web'] = shimPath;
22-
config.resolve.alias['solid-js/jsx-runtime$'] = jsxRuntimeShimPath;
23-
config.resolve.alias['solid-js/jsx-dev-runtime$'] = jsxRuntimeShimPath;
24-
25-
config.plugins = config.plugins || [];
26-
config.plugins.push(new Webpack.NormalModuleReplacementPlugin(/^solid-js\/web$/, shimPath));
27-
config.plugins.push(new Webpack.NormalModuleReplacementPlugin(/^solid-js\/jsx-runtime$/, jsxRuntimeShimPath));
28-
config.plugins.push(new Webpack.NormalModuleReplacementPlugin(/^solid-js\/jsx-dev-runtime$/, jsxRuntimeShimPath));
10+
config.resolve = config.resolve || {};
11+
config.resolve.alias = config.resolve.alias || {};
12+
// `$` keeps the match exact so `@solidjs/web/*` subpaths resolve normally.
13+
config.resolve.alias['@solidjs/web$'] = shimPath;
2914
});
3015
};

‎packages/tanstack-router/package.json‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
22
"name": "@nativescript/tanstack-router",
3-
"version": "0.1.7",
3+
"version": "0.2.0",
44
"description": "TanStack Router for NativeScript",
55
"main": "index.cjs",
66
"types": "index.d.ts",
77
"files": [
88
"index.cjs",
99
"index.mjs",
10-
"index.d.ts",
10+
"*.d.ts",
11+
"*.d.mts",
1112
"solid",
1213
"react",
1314
"nativescript.vite.mjs",
1415
"nativescript.webpack.js",
1516
"solid-web-shim.js",
16-
"solid-js-jsx-runtime-shim.js",
1717
"README.md",
1818
"LICENSE"
1919
],
@@ -74,16 +74,14 @@
7474
"license": "Apache-2.0",
7575
"homepage": "https://github.com/NativeScript/tanstack",
7676
"readmeFilename": "README.md",
77-
"dependencies": {
78-
"@tanstack/router-plugin": "~1.167.0"
79-
},
8077
"peerDependencies": {
81-
"@nativescript-community/solid-js": ">=0.1.0",
78+
"@nativescript-community/solid-js": ">=2.0.0",
8279
"@nativescript-community/react": ">=0.1.0",
8380
"@nativescript/core": ">=9.0.0",
84-
"solid-js": ">=1.9.0",
81+
"solid-js": ">=2.0.0 <3.0.0",
82+
"@solidjs/web": ">=2.0.0 <3.0.0",
8583
"react": ">=19.0.0",
86-
"@tanstack/solid-router": ">=1.169.0",
84+
"@tanstack/solid-router": ">=2.0.0-rc.12 <3.0.0",
8785
"@tanstack/react-router": ">=1.169.0",
8886
"@tanstack/history": ">=1.161.0"
8987
},
@@ -97,6 +95,9 @@
9795
"solid-js": {
9896
"optional": true
9997
},
98+
"@solidjs/web": {
99+
"optional": true
100+
},
100101
"react": {
101102
"optional": true
102103
},
@@ -112,9 +113,9 @@
112113
"typescript": "~5.9.0",
113114
"vitest": "^4.1.5",
114115
"@types/react": "^19.0.0",
115-
"@tanstack/solid-router": "~1.169.0",
116-
"@tanstack/react-router": "~1.169.0",
117-
"@tanstack/history": "~1.161.0",
118-
"@tanstack/router-core": "~1.169.0"
116+
"@tanstack/solid-router": "2.0.0-rc.12",
117+
"@tanstack/react-router": "~1.170.46",
118+
"@tanstack/history": "1.162.5",
119+
"@tanstack/router-core": "1.171.39"
119120
}
120121
}

‎packages/tanstack-router/project.json‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,7 @@
77
"build": {
88
"executor": "nx:run-commands",
99
"options": {
10-
"commands": [
11-
"rm -rf dist/packages/tanstack-router",
12-
"tsc -p packages/tanstack-router/tsconfig.json --noEmit",
13-
"tsup --config packages/tanstack-router/tsup.config.ts",
14-
"cp packages/tanstack-router/package.json dist/packages/tanstack-router/package.json",
15-
"cp packages/tanstack-router/README.md dist/packages/tanstack-router/README.md",
16-
"cp packages/tanstack-router/nativescript.vite.mjs dist/packages/tanstack-router/nativescript.vite.mjs",
17-
"cp packages/tanstack-router/nativescript.webpack.js dist/packages/tanstack-router/nativescript.webpack.js",
18-
"cp packages/tanstack-router/solid-web-shim.js dist/packages/tanstack-router/solid-web-shim.js",
19-
"cp packages/tanstack-router/solid-js-jsx-runtime-shim.js dist/packages/tanstack-router/solid-js-jsx-runtime-shim.js",
20-
"cp LICENSE dist/packages/tanstack-router/LICENSE"
21-
],
10+
"commands": ["rm -rf dist/packages/tanstack-router", "tsc -p packages/tanstack-router/tsconfig.json --noEmit", "tsup --config packages/tanstack-router/tsup.config.ts", "cp packages/tanstack-router/package.json dist/packages/tanstack-router/package.json", "cp packages/tanstack-router/README.md dist/packages/tanstack-router/README.md", "cp packages/tanstack-router/nativescript.vite.mjs dist/packages/tanstack-router/nativescript.vite.mjs", "cp packages/tanstack-router/nativescript.webpack.js dist/packages/tanstack-router/nativescript.webpack.js", "cp packages/tanstack-router/solid-web-shim.js dist/packages/tanstack-router/solid-web-shim.js", "cp LICENSE dist/packages/tanstack-router/LICENSE"],
2211
"parallel": false
2312
},
2413
"outputs": ["{workspaceRoot}/dist/packages/tanstack-router"]

‎packages/tanstack-router/solid-js-jsx-runtime-shim.js‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)