From 3896f15138f0ac6ca0a7f3c52d01fc5b1ddb62df Mon Sep 17 00:00:00 2001 From: MarkXian Date: Sat, 25 Jul 2026 18:28:02 +0800 Subject: [PATCH] fix(solid-router): respect wrapInSuspense --- packages/solid-router/src/Match.tsx | 10 ++++++- packages/solid-router/tests/Matches.test.tsx | 31 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/solid-router/src/Match.tsx b/packages/solid-router/src/Match.tsx index 205e778689..f5f7da13c4 100644 --- a/packages/solid-router/src/Match.tsx +++ b/packages/solid-router/src/Match.tsx @@ -91,7 +91,15 @@ export const Match = (props: { matchId: string }) => { ? resolvedNoSsr : currentMatchState().ssr === 'data-only' - const ResolvedSuspenseBoundary = () => Solid.Suspense + const ResolvedSuspenseBoundary = () => + route().options.wrapInSuspense === false + ? SafeFragment + : (route().options.wrapInSuspense ?? + (resolvePendingComponent() || + (route().options.errorComponent as any)?.preload || + resolvedNoSsr)) + ? Solid.Suspense + : SafeFragment const ResolvedCatchBoundary = () => routeErrorComponent() ? CatchBoundary : SafeFragment diff --git a/packages/solid-router/tests/Matches.test.tsx b/packages/solid-router/tests/Matches.test.tsx index 7bece830bb..a7e3e6da3a 100644 --- a/packages/solid-router/tests/Matches.test.tsx +++ b/packages/solid-router/tests/Matches.test.tsx @@ -155,6 +155,37 @@ test('should show pendingComponent of root route', async () => { expect(await rendered.findByTestId('root-content')).toBeInTheDocument() }) +test('wrapInSuspense false prevents route pendingComponent suspense fallback', async () => { + const gate = createControlledPromise() + const history = createMemoryHistory({ initialEntries: ['/posts'] }) + const root = createRootRoute({ + component: () => , + }) + const postsRoute = createRoute({ + getParentRoute: () => root, + path: '/posts', + wrapInSuspense: false, + pendingComponent: () =>
Loading
, + loader: () => gate, + component: () =>
Posts content
, + }) + + const router = createRouter({ + routeTree: root.addChildren([postsRoute]), + history, + defaultPendingMs: 0, + }) + + render(() => ) + + await waitFor(() => expect(router.state.status).toBe('pending')) + expect(screen.queryByTestId('posts-pending')).not.toBeInTheDocument() + + gate.resolve() + + expect(await screen.findByText('Posts content')).toBeInTheDocument() +}) + test('useMatchRoute follows superseding pending locations', async () => { const aGate = createControlledPromise() const bGate = createControlledPromise()