Skip to content
Open
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
17 changes: 9 additions & 8 deletions docs/router/integrations/nativescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@ by NativeScript and Vite into the nearest `pnpm-workspace.yaml`. Existing
workspace settings and explicit denials are preserved.

```sh
npm run native:ios
npm run native:android
npm run ios
npm run android
```

Requirements for the current stable NativeScript toolchain:

- React 19
- NativeScript 9
- NativeScript 9.1
- `@nativescript-community/react` 19
- `react-nativescript` as an npm alias of `@nativescript-community/react` 19
- `@nativescript/vite` 2.0.3
- Vite 7.3 or newer within the Vite 7 major
- `@nativescript/vite` 8
- Vite 8

NativeScript's stable Vite plugin does not currently support Vite 8. The
NativeScript 9.1 integrates the Vite dev server, including HMR, into the
`ns debug` command, so no additional development scripts are needed. The
initializer adds a compatible Vite version when one is absent and reports a
conflict for an existing incompatible range. `--force` deliberately replaces
that range.
conflict for an existing incompatible range such as Vite 7. `--force`
deliberately replaces that range.

## Sharing an app

Expand Down
27 changes: 13 additions & 14 deletions docs/start/framework/react/guide/nativescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ From a React Start app:
npx @tanstack/router-cli@latest native init
```

The generated development scripts start the Start server and NativeScript app
together:
NativeScript 9.1 integrates the Vite dev server, including HMR, directly into
the CLI, so the generated scripts are plain `ns debug` commands:

```sh
npm run native:ios
npm run native:android
npm run ios
npm run android
```

NativeScript Vite 2.0.3 does not register an HMR server for React, so these
scripts use `ns debug --no-hmr`. Source changes rebuild and restart the native
app instead of hot-patching it.
Run the normal Start dev server (`npm run dev`) in a second terminal when
screens call server functions during development; it hosts them on the
configured Start port.

The Android emulator reaches the host server through `10.0.2.2`. The iOS
simulator uses `127.0.0.1`. A physical device needs a reachable LAN or deployed
Expand Down Expand Up @@ -111,17 +111,16 @@ are sent to `serverFnBase`.

## Production builds

Set the deployed endpoint before invoking a generated build script:
Set the deployed endpoint before invoking a release build:

```sh
TSS_SERVER_FN_BASE=https://app.example.com/_serverFn/ npm run native:build:ios
TSS_SERVER_FN_BASE=https://app.example.com/_serverFn/ npm run native:build:android
TSS_SERVER_FN_BASE=https://app.example.com/_serverFn/ ns build ios --release
TSS_SERVER_FN_BASE=https://app.example.com/_serverFn/ ns build android --release
```

The generated scripts pass NativeScript's `--release` flag. Android release
builds require all four `--key-store-*` options, which can be appended after
`npm run native:build:android --`. Add `--for-device` and the appropriate iOS
signing options when producing an iOS device build.
Android release builds require all four `--key-store-*` options. Add
`--for-device` and the appropriate iOS signing options when producing an iOS
device build.

NativeScript platform signing, App Store configuration, Android manifests, and
device permissions remain standard NativeScript responsibilities. The
Expand Down
19 changes: 9 additions & 10 deletions examples/react/start-nativescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ with the `*-native.tsx` convention.

```sh
pnpm dev
pnpm native:ios
pnpm native:android
pnpm ios
pnpm android
```

The native commands start the Start development server and the NativeScript
debug build together. Production native builds run in release mode and must set
`TSS_SERVER_FN_BASE` to the absolute HTTPS server-function endpoint. Android
release builds also require NativeScript's four `--key-store-*` signing
arguments.
NativeScript 9.1 integrates the Vite dev server into the CLI, so `ns debug`
handles bundling and HMR on its own. Run `pnpm dev` in a second terminal when
screens call Start server functions; it hosts them on port 3000. Production
native builds run in release mode (`ns build ios --release` /
`ns build android --release`) and must set `TSS_SERVER_FN_BASE` to the absolute
HTTPS server-function endpoint. Android release builds also require
NativeScript's four `--key-store-*` signing arguments.

NativeScript renders native `Frame`, `Page`, `ActionBar`, and layout views. It is
not a WebView. iOS interactive swipe-back is provided by the native `Page`
Expand All @@ -27,6 +29,3 @@ The web root route is replaced only in the native bundle. Imports such as
`screens/HomeScreen` resolve to `HomeScreen-native.tsx`, while route and server
modules stay shared. This is the intended migration boundary: DOM and CSS are
not translated into NativeScript controls.

The stable NativeScript Vite 2 integration currently requires Vite 7. This
example pins Vite 7.3.6 while the rest of the monorepo can use Vite 8.
1 change: 0 additions & 1 deletion examples/react/start-nativescript/e2e/run-android.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ async function main() {
ANDROID_HOME:
process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT || tools.sdkRoot,
JAVA_HOME: javaHome,
TSS_NATIVE_PLATFORM: 'android',
TSS_SERVER_FN_BASE: serverFunctionBase,
}

Expand Down
27 changes: 11 additions & 16 deletions examples/react/start-nativescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
"dev": "vite dev --host 0.0.0.0",
"build": "vite build && tsc --noEmit",
"preview": "vite preview",
"native:ios": "concurrently --kill-others-on-fail --names start,ios \"vite dev --host 0.0.0.0\" \"wait-on http-get://127.0.0.1:3000 && cross-env TSS_SERVER_FN_BASE=http://127.0.0.1:3000/_serverFn/ ns debug ios --no-hmr\"",
"native:android": "concurrently --kill-others-on-fail --names start,android \"vite dev --host 0.0.0.0\" \"wait-on http-get://127.0.0.1:3000 && cross-env TSS_SERVER_FN_BASE=http://10.0.2.2:3000/_serverFn/ ns debug android --no-hmr\"",
"native:build:ios": "ns build ios --release --env.production",
"native:build:android": "ns build android --release --env.production",
"native:test:ios": "node e2e/run-ios.mjs",
"native:test:android": "node e2e/run-android.mjs"
"ios": "ns debug ios",
"android": "ns debug android",
"test:ios": "node e2e/run-ios.mjs",
"test:android": "node e2e/run-android.mjs"
},
"dependencies": {
"@nativescript-community/react": "^19.0.0",
"@nativescript/core": "^9.0.20",
"@nativescript/core": "~9.1.0",
"@tanstack/react-nativescript-router": "^0.0.1",
"@tanstack/react-router": "^1.170.15",
"@tanstack/react-start": "^1.168.25",
Expand All @@ -28,21 +26,18 @@
"undom-ng": "^1.1.2"
},
"devDependencies": {
"@nativescript/android": "^9.0.5",
"@nativescript/ios": "^9.0.3",
"@nativescript/types": "^9.0.0",
"@nativescript/vite": "2.0.3",
"@nativescript/android": "~9.1.0",
"@nativescript/ios": "~9.1.0",
"@nativescript/types": "~9.1.0",
"@nativescript/vite": "~8.0.0",
"@tanstack/router-cli": "^1.167.17",
"@types/node": "^22.5.4",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^5.2.0",
"concurrently": "^9.2.1",
"cross-env": "^10.1.0",
"nativescript": "^9.0.6",
"nativescript": "~9.1.0",
"nitro": "^3.0.260311-beta",
"typescript": "^6.0.2",
"vite": "^7.3.6",
"wait-on": "^9.0.3"
"vite": "^8.0.14"
}
}
20 changes: 19 additions & 1 deletion examples/react/start-nativescript/vite.native.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { getCliFlags } from '@nativescript/vite'
import { reactConfig } from '@nativescript/vite/react'
import { tanstackStartNativeScript } from '@tanstack/react-start/plugin/nativescript'
import { defineConfig, mergeConfig } from 'vite'

function isAndroidBuild(): boolean {
// NATIVESCRIPT_BUNDLER_ENV is checked first: the CLI injects it into the
// integrated dev-server process, where the argv --env flags may be absent.
try {
const env = JSON.parse(process.env.NATIVESCRIPT_BUNDLER_ENV ?? '{}')
if (env.android) {
return true
}
if (env.ios || env.visionos) {
return false
}
} catch {
// fall through to the argv flags
}
return Boolean(getCliFlags().android)
}

function getServerFnBase(mode: string): string {
const configured = process.env.TSS_SERVER_FN_BASE
if (configured) {
Expand All @@ -12,7 +30,7 @@ function getServerFnBase(mode: string): string {
'Set TSS_SERVER_FN_BASE to the deployed absolute Start server-function URL before building the native app.',
)
}
return process.env.TSS_NATIVE_PLATFORM === 'android'
return isAndroidBuild()
? 'http://10.0.2.2:3000/_serverFn/'
: 'http://127.0.0.1:3000/_serverFn/'
}
Expand Down
18 changes: 9 additions & 9 deletions packages/react-nativescript-router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ merges an explicit build-script policy without replacing workspace settings.
Then run one of:

```sh
npm run native:ios
npm run native:android
npm run ios
npm run android
```

The current stable toolchain requires React 19, NativeScript 9,
The current stable toolchain requires React 19, NativeScript 9.1,
`@nativescript-community/react` 19, a `react-nativescript` npm alias pointing
to that renderer, `@nativescript/vite@2.0.3`, and Vite 7.3 or newer within the
Vite 7 major.
The initializer refuses an existing Vite 8 range unless `--force` is used.
to that renderer, `@nativescript/vite` 8, and Vite 8.
The initializer refuses an existing incompatible Vite range such as Vite 7
unless `--force` is used.

NativeScript Vite 2.0.3 does not register an HMR server for React. Generated
React scripts therefore use its supported `ns debug --no-hmr` workflow. Source
changes rebuild and restart the native app instead of hot-patching it.
NativeScript 9.1 integrates the Vite dev server, including HMR, into the
`ns debug` command, so the generated scripts are plain `ns debug ios` and
`ns debug android`.

## What is shared

Expand Down
8 changes: 4 additions & 4 deletions packages/react-nativescript-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@
},
"peerDependencies": {
"@nativescript-community/react": ">=19.0.0 <20.0.0",
"@nativescript/core": ">=9.0.0 <10.0.0",
"@nativescript/core": ">=9.1.0",
"dominative": ">=0.1.2",
"react": ">=19.0.0 <20.0.0",
"react-nativescript": ">=19.0.0 <20.0.0",
"undom-ng": ">=1.1.2",
"vite": ">=7.3.0 <8.0.0"
"vite": ">=8.0.0"
},
"peerDependenciesMeta": {
"vite": {
Expand All @@ -111,8 +111,8 @@
},
"devDependencies": {
"@nativescript-community/react": "^19.0.0",
"@nativescript/core": "^9.0.20",
"@nativescript/types": "^9.0.0",
"@nativescript/core": "~9.1.0",
"@nativescript/types": "~9.1.0",
"@types/node": ">=20",
"@types/react": "^19.0.0",
"@vitejs/plugin-react": "^4.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/router-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export async function main() {
`Initialized the ${result.mode} NativeScript target in ${result.root}.`,
)
console.info(
`Run ${result.packageManager} run native:ios or ${result.packageManager} run native:android.`,
`Run ${result.packageManager} run ios or ${result.packageManager} run android.`,
)
},
)
Expand Down
Loading