-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ssr streaming per request #7714
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
schiller-manuel
wants to merge
5
commits into
main
Choose a base branch
from
ssr-streaming-request
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.
+9,001
−275
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
41fe503
ssr streaming per request
schiller-manuel f416256
fix solid streaming
schiller-manuel 238ca69
add streaming assertions
schiller-manuel e19c8a9
remove deferStream from Await in solid
schiller-manuel 400192c
ci: apply automated fixes
autofix-ci[bot] 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
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
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
41 changes: 41 additions & 0 deletions
41
e2e/react-start/streaming-ssr/src/routes/streaming-policy.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,41 @@ | ||
| import { Await, createFileRoute, useRouter } from '@tanstack/react-router' | ||
| import { Suspense } from 'react' | ||
|
|
||
| export const Route = createFileRoute('/streaming-policy')({ | ||
| loader: () => { | ||
| return { | ||
| immediate: 'Immediate policy content', | ||
| deferred: new Promise<string>((resolve) => { | ||
| setTimeout(() => resolve('Deferred policy content'), 100) | ||
| }), | ||
| } | ||
| }, | ||
| component: StreamingPolicyRoute, | ||
| }) | ||
|
|
||
| function StreamingPolicyRoute() { | ||
| const router = useRouter() | ||
| const loaderData = Route.useLoaderData() | ||
| const serverSsr = router.serverSsr | ||
| const render = serverSsr?.shouldStream('render') | ||
| const head = serverSsr?.shouldStream('head') | ||
|
|
||
| return ( | ||
| <div style={{ padding: '20px' }}> | ||
| <h2>Streaming Policy Test</h2> | ||
| <div data-testid="policy-render" suppressHydrationWarning> | ||
| {String(render)} | ||
| </div> | ||
| <div data-testid="policy-head" suppressHydrationWarning> | ||
| {String(head)} | ||
| </div> | ||
| <div data-testid="policy-immediate">{loaderData.immediate}</div> | ||
| <Suspense fallback={<div>Loading policy content...</div>}> | ||
| <Await | ||
| promise={loaderData.deferred} | ||
| children={(value) => <div data-testid="policy-deferred">{value}</div>} | ||
| /> | ||
| </Suspense> | ||
| </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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { | ||
| createStartHandler, | ||
| defaultStreamHandler, | ||
| } from '@tanstack/react-start/server' | ||
| import defaultServerEntry, { | ||
| createServerEntry, | ||
| } from '@tanstack/react-start/server-entry' | ||
| import type { SsrStreamingResolverResult } from '@tanstack/react-start/server' | ||
|
|
||
| type SsrStreamingOverride = { | ||
| render?: boolean | ||
| head?: boolean | ||
| } | ||
|
|
||
| function getStreamingPolicy(request: Request): SsrStreamingResolverResult { | ||
| const url = new URL(request.url) | ||
|
|
||
| switch (url.searchParams.get('streaming')) { | ||
| case 'all': | ||
| return { | ||
| render: true, | ||
| head: true, | ||
| } | ||
| case 'none': | ||
| return { | ||
| render: false, | ||
| } | ||
| case 'render-only': | ||
| return { | ||
| render: true, | ||
| } | ||
| case 'head-only': | ||
| return { | ||
| render: false, | ||
| head: true, | ||
| } | ||
| default: | ||
| return undefined | ||
| } | ||
| } | ||
|
|
||
| function getStreamingOverride( | ||
| request: Request, | ||
| ): SsrStreamingOverride | undefined { | ||
| return getStreamingPolicy(request) | ||
| } | ||
|
|
||
| const handler = createStartHandler({ | ||
| handler: defaultStreamHandler, | ||
| ssr: { | ||
| streaming: ({ request }) => getStreamingPolicy(request), | ||
| }, | ||
| }) | ||
|
|
||
| export default createServerEntry({ | ||
| fetch(request) { | ||
| if (process.env.STREAMING_SSR_ENTRY_FORM === 'default-entry') { | ||
| return defaultServerEntry.fetch(request, { | ||
| ssr: { | ||
| streaming: getStreamingOverride(request), | ||
| }, | ||
| } as any) | ||
| } | ||
|
|
||
| return handler(request) | ||
| }, | ||
| }) | ||
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
2 changes: 2 additions & 0 deletions
2
e2e/react-start/streaming-ssr/tests/preview-streaming.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
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
49 changes: 49 additions & 0 deletions
49
e2e/react-start/streaming-ssr/tests/streaming-policy.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,49 @@ | ||
| import { expect, test } from './fixtures' | ||
|
|
||
| const streamingEntryForm = | ||
| process.env.STREAMING_SSR_ENTRY_FORM ?? 'create-start-handler' | ||
|
|
||
| test.describe(`ssr.streaming policy (${streamingEntryForm})`, () => { | ||
| test('resolves render and head channels from the request', async ({ | ||
| request, | ||
| }) => { | ||
| const cases = [ | ||
| ['all', 'true', 'true'], | ||
| ['none', 'false', 'false'], | ||
| ['render-only', 'true', 'false'], | ||
| ['head-only', 'false', 'true'], | ||
| ] as const | ||
|
|
||
| for (const [mode, render, head] of cases) { | ||
| const response = await request.get(`/streaming-policy?streaming=${mode}`) | ||
| const html = await response.text() | ||
|
|
||
| expect(response.ok()).toBe(true) | ||
| expect(html).toContain(`<div data-testid="policy-render">${render}</div>`) | ||
| expect(html).toContain(`<div data-testid="policy-head">${head}</div>`) | ||
| } | ||
| }) | ||
|
|
||
| test.describe('with JavaScript disabled', () => { | ||
| test.use({ javaScriptEnabled: false }) | ||
|
|
||
| for (const mode of ['none', 'head-only'] as const) { | ||
| test(`renders the full policy page when streaming=${mode}`, async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto(`/streaming-policy?streaming=${mode}`) | ||
|
|
||
| await expect(page.getByTestId('policy-render')).toContainText('false') | ||
| await expect(page.getByTestId('policy-head')).toContainText( | ||
| mode === 'head-only' ? 'true' : 'false', | ||
| ) | ||
| await expect(page.getByTestId('policy-immediate')).toContainText( | ||
| 'Immediate policy content', | ||
| ) | ||
| await expect(page.getByTestId('policy-deferred')).toContainText( | ||
| 'Deferred policy content', | ||
| ) | ||
| }) | ||
| } | ||
| }) | ||
| }) |
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.
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/router
Length of output: 226
🏁 Script executed:
Repository: TanStack/router
Length of output: 50374
🏁 Script executed:
Repository: TanStack/router
Length of output: 29440
🏁 Script executed:
Repository: TanStack/router
Length of output: 22769
Remove the
as anycast ondefaultServerEntry.fetch.RequestOptions<TRegister>already exposesssr.streaming, so this just silences the type check at the call site.🤖 Prompt for AI Agents
Source: Coding guidelines