Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 0 additions & 16 deletions packages/solid-router/src/Match.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,22 +375,6 @@ export const MatchInner = (): any => {
</Solid.Match>
<Solid.Match when={currentMatch().status === 'error'}>
{(_) => {
if (isServer ?? router.isServer) {
const RouteErrorComponent =
(route().options.errorComponent ??
router.options.defaultErrorComponent) ||
ErrorComponent

return (
<RouteErrorComponent
error={currentMatch().error}
info={{
componentStack: '',
}}
/>
)
}

throw currentMatch().error
}}
</Solid.Match>
Expand Down
13 changes: 10 additions & 3 deletions packages/solid-router/tests/server/errorComponent.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest'
import { describe, expect, it, vi } from 'vitest'
import { renderToStringAsync } from 'solid-js/web'
import {
RouterProvider,
Expand All @@ -11,6 +11,7 @@ import {
describe('errorComponent (server)', () => {
it('renders the route error component when a loader throws during SSR', async () => {
const rootRoute = createRootRoute()
const onCatch = vi.fn()

const indexRoute = createRoute({
getParentRoute: () => rootRoute,
Expand All @@ -19,8 +20,11 @@ describe('errorComponent (server)', () => {
throw new Error('loader boom')
},
component: () => <div>Index route</div>,
errorComponent: ({ error }) => (
<div data-testid="error-component">Route error: {error.message}</div>
onCatch,
errorComponent: ({ error, reset }) => (
<div data-testid="error-component">
Route error: {error.message} reset:{typeof reset}
</div>
),
})

Expand All @@ -38,10 +42,13 @@ describe('errorComponent (server)', () => {
const html = await renderToStringAsync(() => (
<RouterProvider router={router} />
))
const normalizedHtml = html.replace(/<!--[\s\S]*?-->/g, '')

expect(router.state.statusCode).toBe(500)
expect(onCatch).toHaveBeenCalledTimes(1)
expect(html).toContain('data-testid="error-component"')
expect(html).toContain('loader boom')
expect(normalizedHtml).toContain('reset:function')
expect(html).not.toContain('Index route')
})
})
Loading