Skip to content

Refactor: Move core SSR functions into its own packages #4495

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
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
62c0fd3
create router-core-ssr package
nlynzaad Jun 21, 2025
ca70923
rename Serializer interface to be more router generic
nlynzaad Jun 21, 2025
6039d23
add core ssr utilities to router-core-ssr
nlynzaad Jun 21, 2025
b7cd937
update start-client-core to use router-core-ssr
nlynzaad Jun 21, 2025
59af218
update start-server-core to use router-core-ssr
nlynzaad Jun 21, 2025
7188dfb
add react-router-ssr package
nlynzaad Jun 21, 2025
0f93022
centralize react ssr functions into react-router-ssr
nlynzaad Jun 21, 2025
115a11c
update import of Serializer type for react-router and solid-router pa…
nlynzaad Jun 21, 2025
c2afabe
update react-start-client and react-start-server to use react-router-ssr
nlynzaad Jun 21, 2025
d28ad03
update pnpm lock file
nlynzaad Jun 21, 2025
1bdb233
update react-router-ssr readme
nlynzaad Jun 21, 2025
39e96c3
update router-core-ssr readme
nlynzaad Jun 21, 2025
1944ca4
ensure renaming of Serializer is non-breaking of react-router and sol…
nlynzaad Jun 21, 2025
e27acf4
rather re-export StartSerializer and mark as deprecated for use in St…
nlynzaad Jun 21, 2025
c738087
re-export client and server functions from router-core-ssr
nlynzaad Jun 21, 2025
9e71ca3
Separate react SSR rendering and handler logic.
nlynzaad Jun 21, 2025
a3b8977
rename Client rendering component in new react-router-ssr
nlynzaad Jun 21, 2025
4a4c501
add an option to provide own children to RouterClient.
nlynzaad Jun 21, 2025
506d7c7
update react basic-ssr examples
nlynzaad Jun 21, 2025
f3ca9da
ci: apply automated fixes
autofix-ci[bot] Jun 22, 2025
82502c8
update router-core-ssr to router-ssr-core
nlynzaad Jun 22, 2025
1644cca
cleanup react-router-ssr vite config
nlynzaad Jun 22, 2025
b6c61d6
add solid-router-ssr package
nlynzaad Jun 22, 2025
f585c1b
implement generic solid ssr logic in solid-router-ssr
nlynzaad Jun 22, 2025
78d3481
ci: apply automated fixes
autofix-ci[bot] Jun 22, 2025
37b4b92
add solid basic ssr example
nlynzaad Jun 22, 2025
977f7c2
Merge remote-tracking branch 'origin/router-ssr' into router-ssr
nlynzaad Jun 22, 2025
cd440c1
resolve esbuild error on router-ssr-core
nlynzaad Jun 22, 2025
72f38a0
update pnpm lock file
nlynzaad Jun 22, 2025
cd8c242
ci: apply automated fixes
autofix-ci[bot] Jun 22, 2025
06b39e4
refactor: use agnostic naming for render helpers
SeanCassiere Jun 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions examples/react/basic-ssr-file-based/package.disabled.json

This file was deleted.

34 changes: 34 additions & 0 deletions examples/react/basic-ssr-file-based/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "tanstack-router-react-example-basic-ssr-file-based",
"private": true,
"type": "module",
"scripts": {
"dev": "node server",
"build": "npm run build:client && npm run build:server",
"build:client": "vite build",
"build:server": "vite build --ssr",
"serve": "NODE_ENV=production node server",
"debug": "node --inspect-brk server"
},
"dependencies": {
"@tanstack/react-router": "^1.121.27",
"@tanstack/react-router-ssr": "^1.121.32",
"@tanstack/router-plugin": "^1.121.29",
"compression": "^1.8.0",
"express": "^4.21.2",
"get-port": "^7.1.0",
"isbot": "^5.1.28",
"node-fetch": "^3.3.2",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@tanstack/react-router-devtools": "^1.121.27",
"@types/express": "^4.17.23",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.1",
"@vitejs/plugin-react": "^4.5.2",
"typescript": "^5.8.3",
"vite": "^6.3.5"
}
}
Binary file not shown.
12 changes: 11 additions & 1 deletion examples/react/basic-ssr-file-based/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'node:path'
import express from 'express'
import getPort, { portNumbers } from 'get-port'
import * as zlib from 'node:zlib'

const isTest = process.env.NODE_ENV === 'test' || !!process.env.VITE_TEST_BUILD

Expand Down Expand Up @@ -38,9 +39,18 @@ export async function createServer(
// use vite's connect instance as middleware
app.use(vite.middlewares)
} else {
app.use((await import('compression')).default())
app.use(
(await import('compression')).default({
brotli: {
flush: zlib.constants.BROTLI_OPERATION_FLUSH,
},
flush: zlib.constants.Z_SYNC_FLUSH,
}),
)
}

if (isProd) app.use(express.static('./dist/client'))

app.use('*', async (req, res) => {
try {
const url = req.originalUrl
Expand Down
5 changes: 2 additions & 3 deletions examples/react/basic-ssr-file-based/src/entry-client.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { hydrateRoot } from 'react-dom/client'

import { StartClient } from '@tanstack/react-start'
import { RouterClient } from '@tanstack/react-router-ssr/client'
import { createRouter } from './router'

const router = createRouter()

hydrateRoot(document, <StartClient router={router} />)
hydrateRoot(document, <RouterClient router={router} />)
15 changes: 12 additions & 3 deletions examples/react/basic-ssr-file-based/src/entry-server.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { pipeline } from 'node:stream/promises'
import {
RouterServer,
createRequestHandler,
defaultStreamHandler,
} from '@tanstack/react-start/server'
renderRouterToString,
} from '@tanstack/react-router-ssr/server'
import { createRouter } from './router'
import type express from 'express'
import './fetch-polyfill'
Expand All @@ -18,6 +19,7 @@ export async function render({
}) {
// Convert the express request to a fetch request
const url = new URL(req.originalUrl || req.url, 'https://localhost:3000').href

const request = new Request(url, {
method: req.method,
headers: (() => {
Expand Down Expand Up @@ -47,11 +49,18 @@ export async function render({
})

// Let's use the default stream handler to create the response
const response = await handler(defaultStreamHandler)
const response = await handler(({ responseHeaders, router }) =>
renderRouterToString({
responseHeaders,
router,
children: <RouterServer router={router} />,
}),
)

// Convert the fetch response back to an express response
res.statusMessage = response.statusText
res.status(response.status)

response.headers.forEach((value, name) => {
res.setHeader(name, value)
})
Expand Down
Loading
Loading