-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
Which project does this relate to?
Start
Describe the bug
Hello!
When I try to catch errors thrown in server functions within an error boundary at the client side, the error is displayed in the standard format for one millisecond before my custom is displayed. Like flashing once.
This happens even I catch them in the default error boundary defined in root route.
Any ideas?
Your Example Website or App
https://github.com/SihirliDev/serverFnTest
Steps to Reproduce the Bug or Issue
- Install the github repo
- Run it
- You'll see the flashing error message when the server function "getPeopleFromDB" executes. It mimics api call throwing an error like this:
await new Promise((resolve) => setTimeout(resolve, 2000)) // simulating data fetch from DB
// Simulating error:
throw new Error("Something happened on the db server side.")
Here is a video of the the errors displaying: https://github.com/user-attachments/assets/f68a96b0-f646-415b-9ea8-98f3622eda0a
And this is the whole code for getPeople.ts
import { createServerFn } from '@tanstack/react-start'
export const getPeopleFromDB = createServerFn({ method: 'GET' })
.inputValidator((dataFormat?: number) => dataFormat)
.handler(async () => {
try {
await new Promise((resolve) => setTimeout(resolve, 2000)) // simulating data fetch from DB
// Simulating error:
throw new Error("Something happened on the db server side.")
const dbQueryResult = [
{ id: 1, name: 'Jack' },
{ id: 2, name: 'Ashley' },
{ id: 3, name: 'Michael' },
]
return {
data: dbQueryResult,
error: null,
}
} catch (error) {
console.log(
'SERVERLOG:' + (error instanceof Error ? error.message : error),
)
return {
data: [],
error: {
status: 500,
name: 'DataServerFnError',
//message: error instanceof Error ? error.message : "SYSTEM ERROR: Unknown database error",
message: 'SYSTEM ERROR: Database error',
},
}
}
})
Expected behavior
I expect the app displays the error only in ErrorBoundary without displaying the default error screen before.
Screenshots or Videos
No response
Platform
-Tanstack Start
-MacOS
-Google Chrome
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels