-
Notifications
You must be signed in to change notification settings - Fork 333
SolidStart: expand docs on rendering modes #1308
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
atilafassina
wants to merge
29
commits into
main
Choose a base branch
from
docs/rendering-modes
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.
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
c83f957
expand docs on rendering modes
atilafassina 28afce1
typo-1
atilafassina 2e8d401
typo-2
atilafassina 7a73d35
typo-3
atilafassina 926ff16
typo-4
atilafassina 08b8670
typooo
atilafassina 41d8ff0
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] 3207564
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] 4bdba75
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] a02ed4c
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] 4d313c3
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] b7fb815
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] 717bca0
big rewording
atilafassina c56434a
Update src/routes/solid-start/building-your-application/rendering-mod…
atilafassina ea97511
Update src/routes/solid-start/building-your-application/rendering-mod…
atilafassina 142c87f
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] e09cc3c
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] bd9cbed
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] d3a447d
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] 2b21ae7
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] 3449f45
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] 5c40d3d
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] c3cb991
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] 0a7f7ec
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] 889b9d7
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] eb2cd49
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] 75c77b2
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] 6738c75
Merge branch 'main' into docs/rendering-modes
kodiakhq[bot] ff476f4
Merge branch 'main' into docs/rendering-modes
kodiakhq[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
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
95 changes: 95 additions & 0 deletions
95
src/routes/solid-start/building-your-application/rendering-modes.mdx
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,95 @@ | ||
| --- | ||
| title: "Rendering Modes" | ||
| --- | ||
|
|
||
| SolidStart has 3 kinds of rendering modes: `sync`, `async`, and `stream`. | ||
| Let's talk about how each of them work and which one to pick. | ||
|
|
||
| :::note | ||
| Default is **stream** and performance-wise should be preferred as a rule-of-thumb. | ||
atilafassina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ::: | ||
|
|
||
| All modes have some degree of Server-Side Rendering, you may need to change them globally depending on your deployment provider. | ||
| And you may prefer to override them for better bot support and SEO. | ||
|
|
||
| ## Impacted Features | ||
atilafassina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| | Feature | sync | async | stream | | ||
| | -------------------- | ----------- | --------------------------- | ----------------------- | | ||
| | Data fetching | Client-side | Server-side (blocking) | Server-side (streaming) | | ||
| | Suspense fallbacks | Yes | No | Yes | | ||
| | Time to first byte | Fast | Slower (waits for all data) | Faster | | ||
| | Total page load time | Slower | Fast (server fetches) | Faster (progressive) | | ||
|
|
||
| ### Sync Mode | ||
|
|
||
| Uses [`renderToString`](/reference/rendering/render-to-string) to render the page from Solid's core to render the page synchronously. | ||
| All async features are disabled and the page is rendered as soon as possible and sent to the client-side where data fetching will happen post-hydration. | ||
|
|
||
| ### Async Mode | ||
|
|
||
| Uses [`renderToStringAsync`](/reference/rendering/render-to-string-async) to render the page from Solid's core to render the page asynchronously. | ||
| All Suspense boundares are resolved and rendered before being sent to the client-side. | ||
atilafassina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| No suspense fallbacks are shown in the browser, which makes this mode ideal for SEO optimizations and bot support. | ||
|
|
||
atilafassina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ### Stream Mode | ||
|
|
||
| Uses [`renderToStream`](/reference/rendering/render-to-stream) to render the page from Solid's core to render the page streaming. | ||
| Leveraging [TransformableStream](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) to progressively send the HTML to the client-side. | ||
|
|
||
| This mode is ideal for performance and future-friendly apps. . | ||
atilafassina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Global Configuration | ||
|
|
||
| The modes can be defined app-wide via the configuration file or via the [`entry-server.tsx`](/solid-start/reference/entrypoints/entry-server) file. | ||
|
|
||
| ```tsx title="app.config.ts" | ||
| import { defineConfig } from "@solidjs/start/config"; | ||
|
|
||
| export default defineConfig({ | ||
| mode: "stream", | ||
| }); | ||
| ``` | ||
|
|
||
| The value in [`entry-server.tsx`](/solid-start/reference/entrypoints/entry-server) overrides the value in [`app.config.ts`](/solid-start/reference/entrypoints/app-config). | ||
|
|
||
| ```tsx title="src/entry-server.tsx" | ||
| import { createHandler, StartServer } from "@solidjs/start/server"; | ||
|
|
||
| export default createHandler(() => ( | ||
| <StartServer document={...} mode="async" /> | ||
atilafassina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ), { | ||
| mode: "async" | ||
| }); | ||
| ``` | ||
|
|
||
| ## Per-Route Configuration | ||
|
|
||
| The optional secondary parameter in [`createHandler`](/solid-start/reference/server/create-handler) can be an object or a function that receives the `RequestEvent` and returns an object with the mode to use for the route. | ||
|
|
||
| ```tsx title="src/entry-server.tsx" | ||
| import { createHandler, StartServer } from "@solidjs/start/server"; | ||
|
|
||
| export default createHandler(() => ( | ||
| <StartServer document={...} /> | ||
| ), { | ||
| mode: (event) => { | ||
| return event.request.url.includes("/special-route") ? "async" : "stream"; | ||
atilafassina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| It can also be used for bot detection via the `userAgent` property of the `RequestEvent`. | ||
|
|
||
| ```tsx title="src/entry-server.tsx" | ||
| import { createHandler, StartServer } from "@solidjs/start/server"; | ||
|
|
||
| export default createHandler(() => ( | ||
| <StartServer document={...} /> | ||
| ), { | ||
| mode: (event) => { | ||
| return isBot(event.request.userAgent) ? "async" : "stream"; | ||
atilafassina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }); | ||
| ``` | ||
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
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.