Skip to content

Commit cc4dac6

Browse files
committed
fix(react-router): preserve functional ssr classification
1 parent 0184d2f commit cc4dac6

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎packages/react-router/src/Match.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ const canWrapInSuspense = (
5656
!route.isRoot ||
5757
(route.options as RootRouteOptions).shellComponent ||
5858
route.options.wrapInSuspense ||
59-
(ssr != null && ssr !== true) ||
59+
ssr === false ||
60+
ssr === 'data-only' ||
6061
!((isServer ?? router.isServer) || router.ssr)
6162

6263
export const Match = React.memo(function MatchImpl({

‎packages/react-router/tests/root-pending-min.test.tsx‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,31 @@ test('root route hydration without a pending boundary preserves component state'
159159
expect(consoleError).not.toHaveBeenCalled()
160160
})
161161

162+
test('an unresolved functional ssr option does not enable a root pending boundary', async () => {
163+
const rootRoute = createRootRoute({
164+
ssr: () => true,
165+
pendingComponent: () => <div>Root pending</div>,
166+
component: () => <div>Root content</div>,
167+
})
168+
const router = createRouter({
169+
routeTree: rootRoute,
170+
history: createMemoryHistory({ initialEntries: ['/'] }),
171+
})
172+
await router.load()
173+
174+
const match = router.stores.matches.get()[0]!
175+
expect(typeof match.ssr).toBe('function')
176+
177+
// Client match construction can expose the unresolved route option before
178+
// hydration replaces it with its transported value.
179+
router.ssr = { manifest: { routes: {} } }
180+
router.isServer = true
181+
const html = renderToString(<RouterProvider router={router} />)
182+
183+
expect(html).not.toContain('<!--$-->')
184+
expect(html).toContain('Root content')
185+
})
186+
162187
test('server rendering uses the root pending boundary inside its document shell', async () => {
163188
const gate = createControlledPromise<void>()
164189
const rootRoute = createRootRoute({

0 commit comments

Comments
 (0)