Skip to content

Commit 7e40e8d

Browse files
docs: Clarify popstate handling in caching exercise
1 parent 11abcbc commit 7e40e8d

File tree

1 file changed

+4
-3
lines changed
  • exercises/04.router/05.problem.cache/ui

1 file changed

+4
-3
lines changed

exercises/04.router/05.problem.cache/ui/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ function Root() {
5454
setNextLocation(nextLocation)
5555
// 🐨 get the historyKey from window.history.state?.key (or fallback to a new one with generateKey)
5656

57-
// 🐨 if the contentCache does not have an entry for the historyKey, then trigger this update:
57+
// 🐨 if the contentCache has an entry for the historyKey, then setContentKey(historyKey) directly.
58+
// (⚠️ no startTransition needed here because the content is already available).
59+
// 🐨 otherwise, fetch new content and wrap the update in startTransition:
5860
const fetchPromise = fetchContent(nextLocation)
5961
const nextContentPromise = createFromFetch(fetchPromise)
6062
// 🐨 use the historyKey to add the nextContentPromise in the contentCache
61-
62-
// 🐨 change this to setContentKey(historyKey)
63+
// 🐨 and change this to setContentKey(historyKey)
6364
startTransition(() => setContentPromise(nextContentPromise))
6465
}
6566
window.addEventListener('popstate', handlePopState)

0 commit comments

Comments
 (0)