Skip to content

Commit 13fd8d9

Browse files
docs: Clarify popstate handling in caching exercise
1 parent 11abcbc commit 13fd8d9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
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)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from 'react'
1212
import { createRoot } from 'react-dom/client'
1313
import * as RSC from 'react-server-dom-esm/client'
14-
import { contentCache, useContentCache, generateKey } from './content-cache.js'
14+
import { contentCache, generateKey, useContentCache } from './content-cache.js'
1515
import { ErrorBoundary } from './error-boundary.js'
1616
import { shipFallbackSrc } from './img-utils.js'
1717
import { RouterContext, getGlobalLocation, useLinkHandler } from './router.js'

0 commit comments

Comments
 (0)