From 350493d15cf3cf9cd98fb655ea15b55eedbbb55d Mon Sep 17 00:00:00 2001 From: Ala Ben Aissia Date: Sun, 17 Aug 2025 20:02:53 +0100 Subject: [PATCH 1/2] docs: Clarify popstate handling in caching exercise --- exercises/04.router/05.problem.cache/ui/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/04.router/05.problem.cache/ui/index.js b/exercises/04.router/05.problem.cache/ui/index.js index d198c70..35c6052 100644 --- a/exercises/04.router/05.problem.cache/ui/index.js +++ b/exercises/04.router/05.problem.cache/ui/index.js @@ -61,6 +61,7 @@ function Root() { // 🐨 change this to setContentKey(historyKey) startTransition(() => setContentPromise(nextContentPromise)) + // 🐨 otherwise, setContentKey(historyKey) directly (no transition needed) } window.addEventListener('popstate', handlePopState) return () => window.removeEventListener('popstate', handlePopState) From 62b0edd3cd566afcc4f538a52f06ae1e9b92dbcf Mon Sep 17 00:00:00 2001 From: Ala Ben Aissia Date: Tue, 19 Aug 2025 12:07:43 +0100 Subject: [PATCH 2/2] fix: Avoid unnecessary startTransition on cached popstate navigations --- exercises/04.router/05.solution.cache/ui/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exercises/04.router/05.solution.cache/ui/index.js b/exercises/04.router/05.solution.cache/ui/index.js index 86d7077..5b5cb1a 100644 --- a/exercises/04.router/05.solution.cache/ui/index.js +++ b/exercises/04.router/05.solution.cache/ui/index.js @@ -56,9 +56,10 @@ function Root() { const fetchPromise = fetchContent(nextLocation) const nextContentPromise = createFromFetch(fetchPromise) contentCache.set(historyKey, nextContentPromise) + startTransition(() => setContentKey(historyKey)) + } else { + setContentKey(historyKey) } - - startTransition(() => setContentKey(historyKey)) } window.addEventListener('popstate', handlePopState) return () => window.removeEventListener('popstate', handlePopState)