-
Notifications
You must be signed in to change notification settings - Fork 423
feat: add ssr for tanstack router #1840
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
7 commits
Select commit
Hold shift + click to select a range
e4fca12
feat: add ssr for tanstack router
brenelz e53a7f8
feat: add ssr for tanstack router
cec47d8
fix: revert lockfile change
956d605
fix: revert lockfile change
4a62955
fix: revert lockfile change
7114f2f
fix: routerLoad argument
938afd8
chore: add changeset
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@solidjs/start": patch | ||
| --- | ||
|
|
||
| get ssr working for tanstack router example |
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,23 +1,8 @@ | ||
| import { RouterProvider, createRouter } from "@tanstack/solid-router"; | ||
| import { routeTree } from "./routeTree.gen"; | ||
| import { router } from "./router"; | ||
| import { RouterProvider } from "@tanstack/solid-router"; | ||
|
|
||
| import "./app.css"; | ||
|
|
||
| const router = createRouter({ | ||
| defaultErrorComponent: (err) => <div>{err.error.stack}</div>, | ||
| routeTree, | ||
| defaultPreload: "intent", | ||
| defaultStaleTime: 5000, | ||
| scrollRestoration: true | ||
| }); | ||
|
|
||
| // Register things for typesafety | ||
| declare module "@tanstack/solid-router" { | ||
| interface Register { | ||
| router: typeof router; | ||
| } | ||
| } | ||
|
|
||
| export default function App() { | ||
| return <RouterProvider router={router} />; | ||
| } |
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,4 +1,4 @@ | ||
| // @refresh reload | ||
| import { mount, StartClient } from "@solidjs/start/client"; | ||
| import { mount, StartClientTanstack } from "@solidjs/start/client"; | ||
|
|
||
| mount(() => <StartClient />, document.getElementById("app")!); | ||
| mount(() => <StartClientTanstack />, document.getElementById("app")!); |
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,21 +1,40 @@ | ||
| // @refresh reload | ||
| import { createHandler, StartServer } from "@solidjs/start/server"; | ||
| import { createHandler, FetchEvent, StartServer } from "@solidjs/start/server"; | ||
| import { createMemoryHistory } from "@tanstack/solid-router"; | ||
| import { router } from "./router"; | ||
|
|
||
| export default createHandler(() => ( | ||
| <StartServer | ||
| document={({ assets, children, scripts }) => ( | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <link rel="icon" href="/favicon.ico" /> | ||
| {assets} | ||
| </head> | ||
| <body> | ||
| <div id="app">{children}</div> | ||
| {scripts} | ||
| </body> | ||
| </html> | ||
| )} | ||
| /> | ||
| )); | ||
| const routerLoad = async (event: FetchEvent) => { | ||
| const url = new URL(event.request.url); | ||
| const path = url.href.replace(url.origin, ""); | ||
|
|
||
| router.update({ | ||
| history: createMemoryHistory({ | ||
| initialEntries: [path] | ||
| }) | ||
| }); | ||
|
|
||
| await router.load(); | ||
| }; | ||
|
|
||
| export default createHandler( | ||
| () => ( | ||
| <StartServer | ||
| document={({ assets, children, scripts }) => ( | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <link rel="icon" href="/favicon.ico" /> | ||
| {assets} | ||
| </head> | ||
| <body> | ||
| <div id="app">{children}</div> | ||
| {scripts} | ||
| </body> | ||
| </html> | ||
| )} | ||
| /> | ||
| ), | ||
| undefined, | ||
| routerLoad | ||
| ); |
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,22 @@ | ||
| import { createRouter as createTanstackSolidRouter } from "@tanstack/solid-router"; | ||
| import { routeTree } from "./routeTree.gen"; | ||
|
|
||
| export function createRouter() { | ||
| const router = createTanstackSolidRouter({ | ||
| defaultErrorComponent: err => <div>{err.error.stack}</div>, | ||
| routeTree, | ||
| defaultPreload: "intent", | ||
| defaultStaleTime: 5000, | ||
| scrollRestoration: true | ||
| }); | ||
| return router; | ||
| } | ||
|
|
||
| export const router = createRouter(); | ||
|
|
||
| // Register things for typesafety | ||
| declare module "@tanstack/solid-router" { | ||
| interface Register { | ||
| router: ReturnType<typeof createRouter>; | ||
| } | ||
| } |
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,5 +1,5 @@ | ||
| // @refresh skip | ||
| import "vinxi/client"; | ||
| export { StartClient } from "./StartClient"; | ||
| export { StartClient, StartClientTanstack } from "./StartClient"; | ||
| export { mount } from "./mount"; | ||
|
|
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.