From b0087fd52b194e417a0e9ae7d3e508f4b4ae4d1a Mon Sep 17 00:00:00 2001 From: Yangshun Date: Fri, 1 Aug 2025 11:32:33 +0800 Subject: [PATCH] [web] workspace/sandpack: don't switch bundler URL when timeout --- .../ProjectsChallengeSolutionSection.tsx | 8 +------- .../common/sandpack/SandpackObservability.tsx | 12 ++++++++++++ .../common/sandpack/useSandpackBundlerURL.ts | 18 ++---------------- .../JavaScriptCodingWorkspaceSection.tsx | 8 +------- .../UserInterfaceCodingWorkspaceSavesPage.tsx | 10 ++-------- .../UserInterfaceCodingWorkspaceSection.tsx | 8 +------- ...erfaceCodingWorkspaceSolutionPreviewTab.tsx | 8 +------- 7 files changed, 20 insertions(+), 52 deletions(-) diff --git a/apps/web/src/components/projects/challenges/solutions/ProjectsChallengeSolutionSection.tsx b/apps/web/src/components/projects/challenges/solutions/ProjectsChallengeSolutionSection.tsx index f2f8e00f1..c54adcf07 100644 --- a/apps/web/src/components/projects/challenges/solutions/ProjectsChallengeSolutionSection.tsx +++ b/apps/web/src/components/projects/challenges/solutions/ProjectsChallengeSolutionSection.tsx @@ -8,7 +8,6 @@ import CodingPreferencesProvider from '~/components/global/CodingPreferencesProv import { useColorSchemePreferences } from '~/components/global/color-scheme/ColorSchemePreferencesProvider'; import type { ProjectsChallengeSolutionBundle } from '~/components/projects/challenges/types'; import SandpackObservability from '~/components/workspace/common/sandpack/SandpackObservability'; -import { SandpackTimeout } from '~/components/workspace/common/sandpack/SandpackTimeout'; import { useSandpackBundlerURL } from '~/components/workspace/common/sandpack/useSandpackBundlerURL'; import ProjectsChallengeSolutionWorkspace from './ProjectsChallengeSolutionWorkspace'; @@ -21,8 +20,7 @@ const sandpackO11yInstance = 'projects.challenge_solution'; export default function ProjectsChallengeSolutionSection({ solution }: Props) { const { colorScheme } = useColorSchemePreferences(); - const [bundlerURL, changeToFallbackUrl] = - useSandpackBundlerURL(sandpackO11yInstance); + const bundlerURL = useSandpackBundlerURL(sandpackO11yInstance); const { files, workspace } = solution; return ( @@ -51,10 +49,6 @@ export default function ProjectsChallengeSolutionSection({ solution }: Props) { activeTabScrollIntoView={true} defaultFiles={files} /> - changeToFallbackUrl('timeout')} - /> { + if (sandpackStatus === 'timeout' && !timeoutSentRef.current) { + logEvent('sandpack.timeout', { + instance, + namespace: 'workspace', + }); + timeoutSentRef.current = true; + } + }, [instance, sandpackStatus]); + useEffect(() => { if (loadingStartedRef.current) { return; diff --git a/apps/web/src/components/workspace/common/sandpack/useSandpackBundlerURL.ts b/apps/web/src/components/workspace/common/sandpack/useSandpackBundlerURL.ts index f60f77e81..b0a2b77a1 100644 --- a/apps/web/src/components/workspace/common/sandpack/useSandpackBundlerURL.ts +++ b/apps/web/src/components/workspace/common/sandpack/useSandpackBundlerURL.ts @@ -8,7 +8,7 @@ import { getErrorMessage } from '~/utils/getErrorMessage'; const defaultBundlerURL = 'https://bundler.greatfrontend.io'; const fallbackBundlerURL = 'https://bundler.greatfrontend.com'; -export function useSandpackBundlerURL(instance: string) { +export function useSandpackBundlerURL(instance: string): string { const [url, setUrl] = useGreatStorageLocal( 'workspace:bundler-url', // Change the key if you want to reset the URL in local storage defaultBundlerURL, @@ -17,20 +17,6 @@ export function useSandpackBundlerURL(instance: string) { }, ); - const changeToFallbackUrl = useCallback( - (reason: 'blocked' | 'timeout' | 'unknown') => { - setUrl(fallbackBundlerURL); - logEvent('sandpack.bundler_fallback', { - instance, - namespace: 'workspace', - online: navigator.onLine, - reason, - url: fallbackBundlerURL, - }); - }, - [instance, setUrl], - ); - const pingBundlerURL = useCallback(async () => { try { const response = await fetch(new URL('version.txt', url).toString()); @@ -83,5 +69,5 @@ export function useSandpackBundlerURL(instance: string) { pingBundlerURL(); }, [url, pingBundlerURL]); - return [url, changeToFallbackUrl] as const; + return url; } diff --git a/apps/web/src/components/workspace/javascript/JavaScriptCodingWorkspaceSection.tsx b/apps/web/src/components/workspace/javascript/JavaScriptCodingWorkspaceSection.tsx index f9f3655d7..8acf1492f 100644 --- a/apps/web/src/components/workspace/javascript/JavaScriptCodingWorkspaceSection.tsx +++ b/apps/web/src/components/workspace/javascript/JavaScriptCodingWorkspaceSection.tsx @@ -8,7 +8,6 @@ import type { QuestionJavaScript, QuestionMetadata, } from '~/components/interviews/questions/common/QuestionsTypes'; -import { SandpackTimeout } from '~/components/workspace/common/sandpack/SandpackTimeout'; import JavaScriptCodingWorkspace from '~/components/workspace/javascript/JavaScriptCodingWorkspace'; import { loadLocalJavaScriptQuestionCode } from '~/components/workspace/javascript/JavaScriptCodingWorkspaceCodeStorage'; @@ -39,8 +38,7 @@ export default function JavaScriptCodingWorkspaceSection({ studyListKey, }: Props) { const { colorScheme } = useColorSchemePreferences(); - const [bundlerURL, changeToFallbackUrl] = - useSandpackBundlerURL(sandpackO11yInstance); + const bundlerURL = useSandpackBundlerURL(sandpackO11yInstance); const { files, skeleton, workspace } = question; const loadedCode = loadLocalJavaScriptQuestionCode( @@ -100,10 +98,6 @@ export default function JavaScriptCodingWorkspaceSection({ workspace={workspace} onLanguageChange={onLanguageChange} /> - changeToFallbackUrl('timeout')} - /> - changeToFallbackUrl('timeout')} - /> - changeToFallbackUrl('timeout')} - /> - changeToFallbackUrl('timeout')} - />