Skip to content
Closed
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
8 changes: 8 additions & 0 deletions packages/solid-start-client/src/StartClient.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { RouterProvider } from '@tanstack/solid-router'
import { hydrateStart } from '@tanstack/start-client-core/client'
import { hydrate } from 'solid-js/web'
import type { AnyRouter } from '@tanstack/router-core'

export function StartClient(props: { router: AnyRouter }) {
return <RouterProvider router={props.router} />
}

export function clientHydrate() {
hydrateStart().then((router) => {
hydrate(() => <StartClient router={router} />, document)
})
}
Comment on lines +10 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add error handling for the hydration promise.

The clientHydrate() function lacks error handling for the promise returned by hydrateStart(). If hydration fails, this will result in an unhandled promise rejection, which could silently break the application or cause confusing runtime errors.

Apply this diff to add error handling:

 export function clientHydrate() {
-  hydrateStart().then((router) => {
-    hydrate(() => <StartClient router={router} />, document)
-  })
+  hydrateStart()
+    .then((router) => {
+      hydrate(() => <StartClient router={router} />, document)
+    })
+    .catch((error) => {
+      console.error('Failed to hydrate application:', error)
+      throw error
+    })
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function clientHydrate() {
hydrateStart().then((router) => {
hydrate(() => <StartClient router={router} />, document)
})
}
export function clientHydrate() {
hydrateStart()
.then((router) => {
hydrate(() => <StartClient router={router} />, document)
})
.catch((error) => {
console.error('Failed to hydrate application:', error)
throw error
})
}
🤖 Prompt for AI Agents
In packages/solid-start-client/src/StartClient.tsx around lines 10 to 14,
clientHydrate() currently calls hydrateStart().then(...) without catching
errors; add error handling to avoid unhandled promise rejections by appending a
.catch(...) to the promise chain (or use async/await with try/catch) that logs
the error (using console.error or an existing logger) and optionally handles
fallback behavior (e.g., abort hydration or show a user-facing error), ensuring
the catch provides clear context about the hydration failure.

3 changes: 1 addition & 2 deletions packages/solid-start-client/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { StartClient } from './StartClient'
export { hydrateStart } from '@tanstack/start-client-core/client'
export { StartClient, clientHydrate } from './StartClient'
8 changes: 2 additions & 6 deletions packages/solid-start/src/default-entry/client.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { hydrate } from 'solid-js/web'
import { hydrateStart } from '@tanstack/start-client-core/client'
import { StartClient } from '@tanstack/solid-start/client'
import { clientHydrate } from '@tanstack/solid-start-client'

hydrateStart().then((router) => {
hydrate(() => <StartClient router={router} />, document)
})
clientHydrate()
Loading