-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add initial preact integration #6700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JoviDeCroock
wants to merge
4
commits into
TanStack:main
Choose a base branch
from
JoviDeCroock:preact-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+8,138
−2
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| node_modules | ||
| .DS_Store | ||
| dist | ||
| dist-hash | ||
| dist-ssr | ||
| *.local | ||
|
|
||
| /test-results/ | ||
| /playwright-report/ | ||
| /blob-report/ | ||
| /playwright/.cache/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>TanStack Router Preact E2E</title> | ||
| </head> | ||
| <body> | ||
| <div id="app"></div> | ||
| <script type="module" src="/src/main.tsx"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "name": "tanstack-router-e2e-preact-basic", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite --port 3000", | ||
| "dev:e2e": "vite", | ||
| "build": "vite build && tsc --noEmit", | ||
| "preview": "vite preview", | ||
| "start": "vite", | ||
| "test:e2e": "rm -rf port*.txt; playwright test --project=chromium" | ||
| }, | ||
| "dependencies": { | ||
| "@tanstack/preact-router": "workspace:^", | ||
| "preact": "^10.25.0", | ||
| "preact-render-to-string": "^6.6.5" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "^1.50.1", | ||
| "@preact/preset-vite": "^2.9.4", | ||
| "@tanstack/router-e2e-utils": "workspace:^", | ||
| "typescript": "^5.9.3", | ||
| "vite": "^7.3.1" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { defineConfig, devices } from '@playwright/test' | ||
| import { | ||
| getDummyServerPort, | ||
| getTestServerPort, | ||
| } from '@tanstack/router-e2e-utils' | ||
| import packageJson from './package.json' with { type: 'json' } | ||
|
|
||
| const PORT = await getTestServerPort(packageJson.name) | ||
| const EXTERNAL_PORT = await getDummyServerPort(packageJson.name) | ||
| const baseURL = `http://localhost:${PORT}` | ||
|
|
||
| export default defineConfig({ | ||
| testDir: './tests', | ||
| workers: 1, | ||
| reporter: [['line']], | ||
| globalSetup: './tests/setup/global.setup.ts', | ||
| globalTeardown: './tests/setup/global.teardown.ts', | ||
| use: { | ||
| baseURL, | ||
| }, | ||
| webServer: { | ||
| command: `VITE_NODE_ENV=\"test\" VITE_SERVER_PORT=${PORT} VITE_EXTERNAL_PORT=${EXTERNAL_PORT} pnpm build && pnpm preview --port ${PORT}`, | ||
| url: baseURL, | ||
| reuseExistingServer: !process.env.CI, | ||
| stdout: 'pipe', | ||
| }, | ||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { ...devices['Desktop Chrome'] }, | ||
| }, | ||
| ], | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { render } from 'preact' | ||
| import { useMemo } from 'preact/hooks' | ||
| import { | ||
| Await, | ||
| Link, | ||
| Outlet, | ||
| RouterProvider, | ||
| Suspense, | ||
| createRootRoute, | ||
| createRoute, | ||
| createRouter, | ||
| } from '@tanstack/preact-router' | ||
|
|
||
| const rootRoute = createRootRoute({ | ||
| component: () => ( | ||
| <div> | ||
| <nav> | ||
| <Link to="/" activeOptions={{ exact: true }}> | ||
| Home | ||
| </Link>{' '} | ||
| <Link to="/slow">Slow</Link> | ||
| </nav> | ||
| <Outlet /> | ||
| </div> | ||
| ), | ||
| }) | ||
|
|
||
| const indexRoute = createRoute({ | ||
| getParentRoute: () => rootRoute, | ||
| path: '/', | ||
| component: () => <h1 data-testid="home">Home</h1>, | ||
| }) | ||
|
|
||
| const slowRoute = createRoute({ | ||
| getParentRoute: () => rootRoute, | ||
| path: '/slow', | ||
| component: SlowRouteComponent, | ||
| }) | ||
|
|
||
| function SlowRouteComponent() { | ||
| const promise = useMemo( | ||
| () => | ||
| new Promise<string>((resolve) => { | ||
| setTimeout(() => resolve('Loaded!'), 200) | ||
| }), | ||
| [], | ||
| ) | ||
|
|
||
| return ( | ||
| <div> | ||
| <h1 data-testid="slow-title">Slow Route</h1> | ||
| <Suspense fallback={<div data-testid="suspense-fallback">Loading...</div>}> | ||
| <Await promise={promise}> | ||
| {(value) => <div data-testid="suspense-content">{value}</div>} | ||
| </Await> | ||
| </Suspense> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| const routeTree = rootRoute.addChildren([indexRoute, slowRoute]) | ||
|
|
||
| const router = createRouter({ | ||
| routeTree, | ||
| }) | ||
|
|
||
| render(<RouterProvider router={router} />, document.getElementById('app')!) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { expect, test } from '@playwright/test' | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto('/') | ||
| }) | ||
|
|
||
| test('shows suspense fallback and then resolved content', async ({ page }) => { | ||
| await expect(page.getByTestId('home')).toBeVisible() | ||
|
|
||
| await page.getByRole('link', { name: 'Slow' }).click() | ||
| await expect(page.getByTestId('slow-title')).toBeVisible() | ||
| await expect(page.getByTestId('suspense-fallback')).toBeVisible() | ||
| await expect(page.getByTestId('suspense-content')).toHaveText('Loaded!') | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { e2eStartDummyServer } from '@tanstack/router-e2e-utils' | ||
| import packageJson from '../../package.json' with { type: 'json' } | ||
|
|
||
| export default async function setup() { | ||
| await e2eStartDummyServer(packageJson.name) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { e2eStopDummyServer } from '@tanstack/router-e2e-utils' | ||
| import packageJson from '../../package.json' with { type: 'json' } | ||
|
|
||
| export default async function teardown() { | ||
| await e2eStopDummyServer(packageJson.name) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "baseUrl": ".", | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "jsx": "react-jsx", | ||
| "jsxImportSource": "preact", | ||
| "target": "ESNext", | ||
| "moduleResolution": "Bundler", | ||
| "module": "ESNext", | ||
| "resolveJsonModule": true, | ||
| "allowJs": true, | ||
| "skipLibCheck": true, | ||
| "types": ["vite/client"], | ||
| "paths": { | ||
| "@tanstack/router-e2e-utils": ["../../e2e-utils/src/index.ts"] | ||
| } | ||
| }, | ||
| "exclude": ["node_modules", "dist"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { defineConfig } from 'vite' | ||
| import preact from '@preact/preset-vite' | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [preact()], | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| node_modules | ||
| .DS_Store | ||
| dist | ||
| dist-ssr | ||
| *.local | ||
|
|
||
| /test-results/ | ||
| /playwright-report/ | ||
| /blob-report/ | ||
| /playwright/.cache/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "files.watcherExclude": { | ||
| "**/routeTree.gen.ts": true | ||
| }, | ||
| "search.exclude": { | ||
| "**/routeTree.gen.ts": true | ||
| }, | ||
| "files.readonlyInclude": { | ||
| "**/routeTree.gen.ts": true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # TanStack Router - Basic Example | ||
|
|
||
| A basic example demonstrating the fundamentals of TanStack Router. | ||
|
|
||
| - [TanStack Router Docs](https://tanstack.com/router) | ||
|
|
||
| ## Start a new project based on this example | ||
|
|
||
| To start a new project based on this example, run: | ||
|
|
||
| ```sh | ||
| npx gitpick TanStack/router/tree/main/examples/react/basic basic | ||
| ``` | ||
|
|
||
| ## Getting Started | ||
|
|
||
| Install dependencies: | ||
|
|
||
| ```sh | ||
| pnpm install | ||
| ``` | ||
|
|
||
| Start the development server: | ||
|
|
||
| ```sh | ||
| pnpm dev | ||
| ``` | ||
|
|
||
| ## Build | ||
|
|
||
| Build for production: | ||
|
|
||
| ```sh | ||
| pnpm build | ||
| ``` | ||
|
|
||
| ## About This Example | ||
|
|
||
| This example demonstrates: | ||
|
|
||
| - Basic routing setup | ||
| - Route configuration | ||
| - Navigation | ||
| - Route parameters | ||
| - TanStack Router DevTools |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Vite App</title> | ||
| </head> | ||
| <body> | ||
| <div id="app"></div> | ||
| <script type="module" src="/src/main.tsx"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "tanstack-router-react-example-basic", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite --port=3000", | ||
| "build": "vite build && tsc --noEmit", | ||
| "preview": "vite preview", | ||
| "start": "vite" | ||
| }, | ||
| "dependencies": { | ||
| "@tailwindcss/vite": "^4.1.18", | ||
| "@tanstack/preact-router": "^1.160.0", | ||
| "preact": "^10.25.0", | ||
| "preact-render-to-string": "^6.6.5", | ||
| "redaxios": "^0.5.1", | ||
| "tailwindcss": "^4.1.18" | ||
| }, | ||
| "devDependencies": { | ||
| "@preact/preset-vite": "^2.10.3", | ||
| "typescript": "^5.7.2", | ||
| "vite": "^7.3.1" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit]: test('shows suspense fallback and then resolves content', async ({ page }) => { .... }