-
Notifications
You must be signed in to change notification settings - Fork 14
test: add e2e fixtures for new experimental TanStack Start RSC #651
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 all commits
Commits
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
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
18 changes: 18 additions & 0 deletions
18
packages/vite-plugin-tanstack-start/test/fixtures/start-basic-rc/src/components/Counter.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,18 @@ | ||
| import * as React from 'react' | ||
|
|
||
| /** | ||
| * A client-only interactive counter component. | ||
| * Used as a child slot inside a server-rendered composite component | ||
| * to demonstrate RSC composition with client interactivity. | ||
| */ | ||
| export function Counter() { | ||
| const [count, setCount] = React.useState(0) | ||
| return ( | ||
| <div data-testid="client-counter"> | ||
| <p>Client-side counter: <span data-testid="counter-value">{count}</span></p> | ||
| <button data-testid="counter-button" onClick={() => setCount((c) => c + 1)}> | ||
| Increment | ||
| </button> | ||
| </div> | ||
| ) | ||
| } |
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
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
27 changes: 27 additions & 0 deletions
27
packages/vite-plugin-tanstack-start/test/fixtures/start-basic-rc/src/routes/rsc-basic.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,27 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
| import { fetchRscGreeting, fetchRscUserList } from '~/utils/rsc' | ||
|
|
||
| export const Route = createFileRoute('/rsc-basic')({ | ||
| loader: async () => { | ||
| const [greeting, users] = await Promise.all([ | ||
| fetchRscGreeting(), | ||
| fetchRscUserList(), | ||
| ]) | ||
| return { ...greeting, ...users } | ||
| }, | ||
| component: RscBasicPage, | ||
| }) | ||
|
|
||
| function RscBasicPage() { | ||
| const { Greeting, UserList } = Route.useLoaderData() | ||
| return ( | ||
| <div className="p-2"> | ||
| <h2>RSC Basic Demo</h2> | ||
| <p>This page demonstrates basic React Server Components rendered via <code>renderServerComponent</code>.</p> | ||
| <hr /> | ||
| {Greeting} | ||
| <hr /> | ||
| {UserList} | ||
| </div> | ||
| ) | ||
| } |
26 changes: 26 additions & 0 deletions
26
...ages/vite-plugin-tanstack-start/test/fixtures/start-basic-rc/src/routes/rsc-composite.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,26 @@ | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
| import { CompositeComponent } from '@tanstack/react-start/rsc' | ||
| import { fetchRscCard } from '~/utils/rsc' | ||
| import { Counter } from '~/components/Counter' | ||
|
|
||
| export const Route = createFileRoute('/rsc-composite')({ | ||
| loader: () => fetchRscCard(), | ||
| component: RscCompositePage, | ||
| }) | ||
|
|
||
| function RscCompositePage() { | ||
| const { Card } = Route.useLoaderData() | ||
| return ( | ||
| <div className="p-2"> | ||
| <h2>RSC Composite Demo</h2> | ||
| <p> | ||
| This page demonstrates <code>createCompositeComponent</code> with children slots. | ||
| The card shell is rendered on the server, while the counter inside is a client component. | ||
| </p> | ||
| <hr /> | ||
| <CompositeComponent src={Card}> | ||
| <Counter /> | ||
| </CompositeComponent> | ||
| </div> | ||
| ) | ||
| } |
75 changes: 75 additions & 0 deletions
75
packages/vite-plugin-tanstack-start/test/fixtures/start-basic-rc/src/utils/rsc.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,75 @@ | ||
| import * as React from 'react' | ||
| import { createServerFn } from '@tanstack/react-start' | ||
| import { | ||
| renderServerComponent, | ||
| createCompositeComponent, | ||
| } from '@tanstack/react-start/rsc' | ||
|
|
||
| /** | ||
| * A basic server function that renders a server component using renderServerComponent. | ||
| * The component fetches data on the server and renders it — the fetch logic never | ||
| * reaches the client bundle. | ||
| */ | ||
| export const fetchRscGreeting = createServerFn().handler(async () => { | ||
| // Simulate server-only work (e.g., DB query, secret API call) | ||
| const timestamp = new Date().toISOString() | ||
|
|
||
| const Greeting = await renderServerComponent( | ||
| <div data-testid="rsc-greeting"> | ||
| <h2>Hello from a Server Component!</h2> | ||
| <p>This was rendered on the server at {timestamp}.</p> | ||
| <p> | ||
| This content comes from a React Server Component. The rendering logic | ||
| and any server-only dependencies never reach the client bundle. | ||
| </p> | ||
| </div>, | ||
| ) | ||
|
|
||
| return { Greeting } | ||
| }) | ||
|
|
||
| /** | ||
| * A server function that fetches data and renders it as a server component. | ||
| * Demonstrates data fetching colocated within an RSC. | ||
| */ | ||
| export const fetchRscUserList = createServerFn().handler(async () => { | ||
| const res = await fetch('https://jsonplaceholder.typicode.com/users') | ||
| if (!res.ok) { | ||
| throw new Error('Failed to fetch users for RSC') | ||
| } | ||
| const users = (await res.json()) as Array<{ id: number; name: string; email: string }> | ||
|
Comment on lines
+36
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid hard dependency on live third-party API in e2e fixture path. At Line 36-Line 40, the fixture relies on a public API at request time. This makes RSC tests non-deterministic and vulnerable to external outages/rate limits. Suggested deterministic fallback pattern export const fetchRscUserList = createServerFn().handler(async () => {
- const res = await fetch('https://jsonplaceholder.typicode.com/users')
- if (!res.ok) {
- throw new Error('Failed to fetch users for RSC')
- }
- const users = (await res.json()) as Array<{ id: number; name: string; email: string }>
+ const fallbackUsers: Array<{ id: number; name: string; email: string }> = [
+ { id: 1, name: 'Leanne Graham', email: 'leanne@example.com' },
+ { id: 2, name: 'Ervin Howell', email: 'ervin@example.com' },
+ { id: 3, name: 'Clementine Bauch', email: 'clementine@example.com' },
+ { id: 4, name: 'Patricia Lebsack', email: 'patricia@example.com' },
+ { id: 5, name: 'Chelsey Dietrich', email: 'chelsey@example.com' },
+ ]
+
+ let users = fallbackUsers
+ try {
+ const res = await fetch('https://jsonplaceholder.typicode.com/users')
+ if (res.ok) {
+ users = (await res.json()) as Array<{ id: number; name: string; email: string }>
+ }
+ } catch {
+ // keep deterministic fallback for fixture stability
+ }🤖 Prompt for AI Agents |
||
|
|
||
| const UserList = await renderServerComponent( | ||
| <div data-testid="rsc-user-list"> | ||
| <h3>Users (Server Component)</h3> | ||
| <ul> | ||
| {users.slice(0, 5).map((user) => ( | ||
| <li key={user.id} data-testid={`rsc-user-${user.id}`}> | ||
| {user.name} — {user.email} | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div>, | ||
| ) | ||
|
|
||
| return { UserList } | ||
| }) | ||
|
|
||
| /** | ||
| * A composite component that accepts children slots. | ||
| * The server renders the outer shell, and client components can be | ||
| * passed as children. | ||
| */ | ||
| export const fetchRscCard = createServerFn().handler(async () => { | ||
| const src = await createCompositeComponent( | ||
| (props: { children?: React.ReactNode }) => ( | ||
| <div data-testid="rsc-card" style={{ border: '1px solid #ccc', padding: '16px', borderRadius: '8px' }}> | ||
| <h3>Server-Rendered Card</h3> | ||
| <p>This card shell is rendered on the server.</p> | ||
| <div data-testid="rsc-card-children">{props.children}</div> | ||
| </div> | ||
| ), | ||
| ) | ||
|
|
||
| return { Card: src } | ||
| }) | ||
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
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.
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.
Stabilize post-click counter assertion to avoid async flake.
At Line 100-Line 102, the value is read immediately after click. This can intermittently fail before state commit in slower environments.
Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents