-
-
Notifications
You must be signed in to change notification settings - Fork 146
docs: solid start ssr #562
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,10 @@ | ||
| import { defineConfig } from '@solidjs/start/config' | ||
| import topLevelAwait from 'vite-plugin-top-level-await' | ||
|
|
||
| export default defineConfig({}) | ||
| export default defineConfig({ | ||
| vite: { | ||
| plugins: [ | ||
| topLevelAwait(), | ||
| ], | ||
| }, | ||
| }) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { createRouterClient } from '@orpc/server' | ||
| import { getRequestEvent } from 'solid-js/web' | ||
| import { router } from '~/router' | ||
|
|
||
| if (typeof window !== 'undefined') { | ||
| throw new Error('This file should not be imported in the browser') | ||
| } | ||
|
|
||
| /** | ||
| * This is part of the Optimize SSR setup. | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/integrations/solid-start#optimize-ssr} | ||
| */ | ||
| globalThis.$client = createRouterClient(router, { | ||
| /** | ||
| * Provide initial context if needed. | ||
| * | ||
| * Because this client instance is shared across all requests, | ||
| * only include context that's safe to reuse globally. | ||
| * For per-request context, use middleware context or pass a function as the initial context. | ||
| */ | ||
| context: async () => { | ||
| const headers = getRequestEvent()?.request.headers | ||
|
|
||
| return { | ||
| headers, | ||
| } | ||
| }, | ||
| }) |
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 |
|---|---|---|
| @@ -1,16 +1,23 @@ | ||
| if (typeof window === 'undefined') { | ||
| await import('./orpc.server') | ||
| } | ||
|
|
||
| import type { RouterClient } from '@orpc/server' | ||
| import type { router } from '~/router' | ||
| import { createORPCClient } from '@orpc/client' | ||
| import { RPCLink } from '@orpc/client/fetch' | ||
| import { createORPCSolidQueryUtils } from '@orpc/solid-query' | ||
| import { getRequestEvent } from 'solid-js/web' | ||
|
|
||
| declare global { | ||
| var $client: RouterClient<typeof router> | undefined | ||
| } | ||
|
|
||
| const rpcLink = new RPCLink({ | ||
| const link = new RPCLink({ | ||
| url: new URL('/rpc', typeof window !== 'undefined' ? window.location.href : 'http://localhost:3000'), | ||
| headers: () => ({ | ||
| Authorization: 'Bearer default-token', | ||
| }), | ||
| headers: () => Object.fromEntries(getRequestEvent()?.request.headers ?? []), | ||
| }) | ||
|
|
||
| export const client: RouterClient<typeof router> = createORPCClient(rpcLink) | ||
| export const client: RouterClient<typeof router> = globalThis.$client ?? createORPCClient(link) | ||
|
|
||
| export const orpc = createORPCSolidQueryUtils(client) |
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.
Move QueryClient instantiation outside the component to prevent recreation on each render.
The QueryClient is being instantiated inside the App component, which means a new instance will be created on every render. This can lead to performance issues and loss of cached data.
📝 Committable suggestion
🤖 Prompt for AI Agents