From 4ef6c67bd8565168a8a7e83858eb471c3f877fba Mon Sep 17 00:00:00 2001 From: Madison Date: Thu, 4 Sep 2025 05:44:42 -0500 Subject: [PATCH] Resolve error handling, and SSR issues --- docs/src/components/mdx/dynamic-code-block.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/src/components/mdx/dynamic-code-block.tsx b/docs/src/components/mdx/dynamic-code-block.tsx index baf7f3d50..def1c0016 100644 --- a/docs/src/components/mdx/dynamic-code-block.tsx +++ b/docs/src/components/mdx/dynamic-code-block.tsx @@ -1,5 +1,6 @@ 'use client'; +import { runAsynchronously } from "@stackframe/stack-shared/dist/utils/promises"; import { useEffect, useState } from "react"; import { codeToHtml } from "shiki"; import { useCodeOverlay } from "../../hooks/use-code-overlay"; @@ -24,7 +25,9 @@ export function DynamicCodeblock({ code, language = 'tsx', title, useOverlay = t // Handle window resize for responsive positioning useEffect(() => { const updateWindowWidth = () => { - setWindowWidth(window.innerWidth); + if (typeof window !== 'undefined') { + setWindowWidth(window.innerWidth); + } }; // Set initial width @@ -39,7 +42,9 @@ export function DynamicCodeblock({ code, language = 'tsx', title, useOverlay = t // Handle scroll to fade button when near bottom useEffect(() => { const handleScroll = () => { - const scrollTop = window.pageYOffset || document.documentElement.scrollTop; + if (typeof window === 'undefined') return; + + const scrollTop = window.scrollY || document.documentElement.scrollTop; const windowHeight = window.innerHeight; const documentHeight = document.documentElement.scrollHeight; @@ -110,10 +115,8 @@ export function DynamicCodeblock({ code, language = 'tsx', title, useOverlay = t // Only highlight code if not using overlay (for fallback) if (!useOverlay) { - // eslint-disable-next-line no-restricted-syntax - updateHighlightedCode().catch(error => { - console.error('Error updating highlighted code:', error); - }); + // Run async function - all errors are handled within the function + runAsynchronously(updateHighlightedCode()); } }, [code, language, useOverlay]);