-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(solid-router): implement navigation transitions #5691
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
58ff44b
wrok on wrapbatch
birkskyum 3dcfe18
isrealbrowser check
birkskyum 41e699d
simplify the solution
brenelz d4e69ff
ci: apply automated fixes
autofix-ci[bot] e1bfa43
update state-updates-during-navigation for react
birkskyum 5f2b2cb
early return null in case of no match
birkskyum 4cc1cfc
work on useMatch
birkskyum b358a9f
ci: apply automated fixes
autofix-ci[bot] 60dda68
skip parallel navigation
birkskyum 772ed17
flaky store update
birkskyum 13470aa
Move startTransition around startViewTransition
birkskyum 7a80426
Fix one unit test
brenelz 5d51095
ci: apply automated fixes
autofix-ci[bot] 8333c6f
Display pending component if defined
birkskyum c5dc9f2
ci: apply automated fixes
autofix-ci[bot] 9d9cb33
rename to resolvePendingComponent
birkskyum a37c72d
remove startTransition from link
birkskyum 860bfa7
cleanup
birkskyum 3dbdc9f
add query test for solid
birkskyum e0364bb
ci: apply automated fixes
autofix-ci[bot] 52749f5
react query test
birkskyum ca69d40
ci: apply automated fixes
autofix-ci[bot] 5ff886c
remove memo
birkskyum 3064313
fix solid
birkskyum 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
Some comments aren't visible on the classic Files Changed page.
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
56 changes: 56 additions & 0 deletions
56
e2e/react-router/basic-react-query-file-based/src/routes/transition/index.tsx
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,56 @@ | ||
| import { Link, createFileRoute } from '@tanstack/react-router' | ||
| import { Suspense, useMemo } from 'react' | ||
| import { queryOptions, useQuery } from '@tanstack/react-query' | ||
| import { z } from 'zod' | ||
|
|
||
| const searchSchema = z.object({ | ||
| n: z.number().default(1), | ||
| }) | ||
|
|
||
| const doubleQueryOptions = (n: number) => | ||
| queryOptions({ | ||
| queryKey: ['transition-double', n], | ||
| queryFn: async () => { | ||
| await new Promise((resolve) => setTimeout(resolve, 1000)) | ||
| return n * 2 | ||
| }, | ||
| placeholderData: (oldData) => oldData, | ||
| }) | ||
|
|
||
| export const Route = createFileRoute('/transition/')({ | ||
| validateSearch: searchSchema, | ||
| loader: ({ context: { queryClient }, location }) => { | ||
| const { n } = searchSchema.parse(location.search) | ||
| return queryClient.ensureQueryData(doubleQueryOptions(n)) | ||
| }, | ||
| component: TransitionPage, | ||
| }) | ||
|
|
||
| function TransitionPage() { | ||
| const search = Route.useSearch() | ||
|
|
||
| const doubleQuery = useMemo( | ||
| () => useQuery(doubleQueryOptions(search.n)), | ||
| [search.n], | ||
| ) | ||
|
|
||
| return ( | ||
| <Suspense fallback="Loading..."> | ||
| <div className="p-2"> | ||
| <Link | ||
| data-testid="increase-button" | ||
| className="border bg-gray-50 px-3 py-1" | ||
| from="/transition" | ||
| search={(s) => ({ n: s.n + 1 })} | ||
| > | ||
| Increase | ||
| </Link> | ||
|
|
||
| <div className="mt-2"> | ||
| <div data-testid="n-value">n: {search.n}</div> | ||
| <div data-testid="double-value">double: {doubleQuery.data}</div> | ||
| </div> | ||
| </div> | ||
| </Suspense> | ||
| ) | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
e2e/react-router/basic-react-query-file-based/tests/transition.spec.ts
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,37 @@ | ||
| import { expect, test } from '@playwright/test' | ||
|
|
||
| test('react-query transitions keep previous data during navigation', async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto('/transition') | ||
|
|
||
| await expect(page.getByTestId('n-value')).toContainText('n: 1') | ||
| await expect(page.getByTestId('double-value')).toContainText('double: 2') | ||
|
|
||
| const bodySnapshots: Array<string> = [] | ||
|
|
||
| const interval = setInterval(async () => { | ||
| const text = await page | ||
| .locator('body') | ||
| .textContent() | ||
| .catch(() => '') | ||
| if (text) bodySnapshots.push(text) | ||
| }, 50) | ||
|
|
||
| await page.getByTestId('increase-button').click() | ||
|
|
||
| await page.waitForTimeout(200) | ||
|
|
||
| clearInterval(interval) | ||
|
|
||
| await expect(page.getByTestId('n-value')).toContainText('n: 2', { | ||
| timeout: 2_000, | ||
| }) | ||
| await expect(page.getByTestId('double-value')).toContainText('double: 4', { | ||
| timeout: 2_000, | ||
| }) | ||
|
|
||
| const sawLoading = bodySnapshots.some((text) => text.includes('Loading...')) | ||
|
|
||
| expect(sawLoading).toBeFalsy() | ||
| }) |
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
48 changes: 48 additions & 0 deletions
48
e2e/solid-router/basic-file-based/src/routes/transition/index.tsx
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,48 @@ | ||
| import { Link, createFileRoute } from '@tanstack/solid-router' | ||
| import { Suspense, createResource } from 'solid-js' | ||
| import { z } from 'zod' | ||
|
|
||
| export const Route = createFileRoute('/transition/')({ | ||
| validateSearch: z.object({ | ||
| n: z.number().default(1), | ||
| }), | ||
| component: Home, | ||
| }) | ||
|
|
||
| function Home() { | ||
| return ( | ||
| <div class="p-2"> | ||
| <Link | ||
| data-testid="increase-button" | ||
| class="border bg-gray-50 px-3 py-1" | ||
| from="/transition" | ||
| search={(s) => ({ n: s.n + 1 })} | ||
| > | ||
| Increase | ||
| </Link> | ||
|
|
||
| <Result /> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| function Result() { | ||
| const searchQuery = Route.useSearch() | ||
|
|
||
| const [doubleQuery] = createResource( | ||
| () => searchQuery().n, | ||
| async (n) => { | ||
| await new Promise((r) => setTimeout(r, 1000)) | ||
| return n * 2 | ||
| }, | ||
| ) | ||
|
|
||
| return ( | ||
| <div class="mt-2"> | ||
| <Suspense fallback="Loading..."> | ||
| <div data-testid="n-value">n: {searchQuery().n}</div> | ||
| <div data-testid="double-value">double: {doubleQuery()}</div> | ||
| </Suspense> | ||
| </div> | ||
| ) | ||
| } |
43 changes: 43 additions & 0 deletions
43
e2e/solid-router/basic-file-based/tests/transition.spec.ts
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,43 @@ | ||
| import { expect, test } from '@playwright/test' | ||
|
|
||
| test('transitions should keep old values visible during navigation', async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto('/transition') | ||
|
|
||
| await expect(page.getByTestId('n-value')).toContainText('n: 1') | ||
| await expect(page.getByTestId('double-value')).toContainText('double: 2') | ||
|
|
||
| const bodyTexts: Array<string> = [] | ||
|
|
||
| const pollInterval = setInterval(async () => { | ||
| const text = await page | ||
| .locator('body') | ||
| .textContent() | ||
| .catch(() => '') | ||
| if (text) bodyTexts.push(text) | ||
| }, 50) | ||
|
|
||
| await page.getByTestId('increase-button').click() | ||
|
|
||
| await page.waitForTimeout(200) | ||
|
|
||
| clearInterval(pollInterval) | ||
|
|
||
| await expect(page.getByTestId('n-value')).toContainText('n: 2', { | ||
| timeout: 2000, | ||
| }) | ||
| await expect(page.getByTestId('double-value')).toContainText('double: 4', { | ||
| timeout: 2000, | ||
| }) | ||
|
|
||
| // With proper transitions, old values should remain visible until new ones arrive | ||
| const hasLoadingText = bodyTexts.some((text) => text.includes('Loading...')) | ||
|
|
||
| if (hasLoadingText) { | ||
| throw new Error( | ||
| 'FAILED: "Loading..." appeared during navigation. ' + | ||
| 'Solid Router should use transitions to keep old values visible.', | ||
| ) | ||
| } | ||
| }) |
Oops, something went wrong.
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.