⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(web): clear shiki stale-chunk reload flag after successful init
justinc8c2d91ae06c
diff --git a/apps/web/src/lib/shiki-highlighter.ts b/apps/web/src/lib/shiki-highlighter.tsindex 723b19c6f..37aef2581 100644--- a/apps/web/src/lib/shiki-highlighter.ts+++ b/apps/web/src/lib/shiki-highlighter.ts@@ -43,6 +43,8 @@ const SHIKI_LANGUAGES = ["yaml",] as const;+const RELOAD_FLAG = "shiki_chunk_reload_attempted";+export function getSharedShikiHighlighter() {if (!shikiHighlighterPromise) {shikiHighlighterPromise = createHighlighter({@@ -57,39 +59,50 @@ export function getSharedShikiHighlighter() {// (worst case: one token type unhighlighted) instead of throwing at// creation. All bundled grammars translate as of Shiki 3.9.1.engine: createJavaScriptRegexEngine({ forgiving: true }),- }).catch((err) => {- // Reset so a subsequent call can retry rather than reusing a- // permanently-rejected promise.- shikiHighlighterPromise = null;-- // A dynamic import failure typically means the browser has a stale- // version of the app (cached HTML referencing old content-hashed chunks)- // and the asset no longer exists after a new deployment. Reloading- // fetches the latest HTML and chunk filenames.- if (- err instanceof TypeError &&- err.message.includes("Failed to fetch dynamically imported module")- ) {- const RELOAD_FLAG = "shiki_chunk_reload_attempted";+ })+ .then((highlighter) => {+ // Initialize succeeded — clear the reload flag so a stale-chunk+ // failure from a later deployment in the same tab can recover via+ // reload instead of being treated as a loop attempt.try {- if (!sessionStorage.getItem(RELOAD_FLAG)) {- sessionStorage.setItem(RELOAD_FLAG, "1");- window.location.reload();- // Return a never-resolving promise so callers wait for the reload- // rather than receiving a rejected promise.- return new Promise<never>(() => {});- }- // Already reloaded once — fail silently so we don't loop.- return Promise.reject(err);+ sessionStorage.removeItem(RELOAD_FLAG);} catch {- // sessionStorage access failed (disabled, private browsing, quota, etc.)- // Skip reload attempt and rethrow the original error.- throw err;+ // sessionStorage unavailable — nothing to clear.+ }+ return highlighter;+ })+ .catch((err) => {+ // Reset so a subsequent call can retry rather than reusing a+ // permanently-rejected promise.+ shikiHighlighterPromise = null;++ // A dynamic import failure typically means the browser has a stale+ // version of the app (cached HTML referencing old content-hashed chunks)+ // and the asset no longer exists after a new deployment. Reloading+ // fetches the latest HTML and chunk filenames.+ if (+ err instanceof TypeError &&+ err.message.includes("Failed to fetch dynamically imported module")+ ) {+ try {+ if (!sessionStorage.getItem(RELOAD_FLAG)) {+ sessionStorage.setItem(RELOAD_FLAG, "1");+ window.location.reload();+ // Return a never-resolving promise so callers wait for the reload+ // rather than receiving a rejected promise.+ return new Promise<never>(() => {});+ }+ // Already reloaded once — fail silently so we don't loop.+ return Promise.reject(err);+ } catch {+ // sessionStorage access failed (disabled, private browsing, quota, etc.)+ // Skip reload attempt and rethrow the original error.+ throw err;+ }}- }- throw err;- });+ throw err;+ });}return shikiHighlighterPromise;