Skip to content

Commit 63075b0

Browse files
committed
fix: Move redirect logic to useEffect to prevent SSR issues
The redirect logic was previously running directly in the component body, which could cause issues with React's rendering and Next.js SSR/hydration. Moving it to useEffect ensures it only runs on the client side after mount. This should fix the Vercel deployment failure.
1 parent 816dc37 commit 63075b0

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

components/nodes/NodeDetails.tsx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -189,27 +189,29 @@ const NodeDetails = () => {
189189

190190
// redirect to correct node ID if the responded node.id doesn't match the URL nodeId
191191
// this handles cases where the node ID has changed or been normalized
192-
const isNodeIdMismatchedBetweenURLandNode =
193-
node && node.id && node.id !== nodeId
194-
if (isNodeIdMismatchedBetweenURLandNode) {
195-
// if we're on /publishers/[publisherId]/nodes/[nodeId], redirect to the correct publisher and node ID
196-
if (_publisherId) {
197-
router.replace(`/publishers/${publisherId}/nodes/${node.id}`)
198-
} else {
199-
// if we're on /nodes/[nodeId], redirect to the correct node ID
200-
router.replace(`/nodes/${node.id}`)
192+
React.useEffect(() => {
193+
const isNodeIdMismatchedBetweenURLandNode =
194+
node && node.id && node.id !== nodeId
195+
if (isNodeIdMismatchedBetweenURLandNode) {
196+
// if we're on /publishers/[publisherId]/nodes/[nodeId], redirect to the correct publisher and node ID
197+
if (_publisherId) {
198+
router.replace(`/publishers/${publisherId}/nodes/${node.id}`)
199+
} else {
200+
// if we're on /nodes/[nodeId], redirect to the correct node ID
201+
router.replace(`/nodes/${node.id}`)
202+
}
201203
}
202-
return null // prevent rendering the component while redirecting
203-
}
204+
}, [node, nodeId, _publisherId, publisherId, router])
204205

205206
// redirect to correct /publishers/[publisherId]/nodes/[nodeId] if publisherId in query is different from the one in node
206207
// usually this happens when publisher changes, e.g. when user claims a node
207-
const isPublisherIdMismatchedBetweenURLandNode =
208-
node && _publisherId && publisherId !== _publisherId
209-
if (isPublisherIdMismatchedBetweenURLandNode) {
210-
router.replace(`/publishers/${publisherId}/nodes/${nodeId}`)
211-
return null // prevent rendering the component while redirecting
212-
}
208+
React.useEffect(() => {
209+
const isPublisherIdMismatchedBetweenURLandNode =
210+
node && _publisherId && publisherId !== _publisherId
211+
if (isPublisherIdMismatchedBetweenURLandNode) {
212+
router.replace(`/publishers/${publisherId}/nodes/${nodeId}`)
213+
}
214+
}, [node, _publisherId, publisherId, nodeId, router])
213215

214216
const shouldShowLoading = isLoading || !router.isReady || !_nodeId
215217
if (shouldShowLoading) {

0 commit comments

Comments
 (0)