Repository navigation
Let Back restore a leaf.page page the visitor has acted on: every Leaf server answers no-cache - #5717
Merged
Merged
Conversation
…f server answers no-cache leaf.page now answers a page's document, state and media under the cache policy the local server uses, so Chrome keeps a page the visitor has acted on in its back/forward cache. The policy has one home, `CACHE_CONTROL` and `IMMUTABLE_CACHE_CONTROL` in `src/leaf/http.py`; the website override, the sample child's copy of it and the Durable Object's `private, no-store` are deleted. Reverses leaf.page's `no-store` choice, per the decision on #4024.
leaf-agent
approved these changes
Nov 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
leaf.page now answers a page's document, state and media under the cache policy the local server already used, so Back restores a page the visitor has acted on from the browser's back/forward cache instead of loading it again. This builds the decision on #4024: one cache policy for every Leaf server.
What changed
The policy now has one home:
CACHE_CONTROL = "no-cache"andIMMUTABLE_CACHE_CONTROL = "private, max-age=31536000, immutable"insrc/leaf/http.py. They are module constants rather thanPageEndpointclass attributes, so no endpoint can override them, and the revision-resource answer uses the second instead of its own copy of the string. The comment above them records the reversal and the cost accepted.Three copies of the old
no-storechoice are deleted:WebsitePageEndpoint.cache_control = "no-store"andmedia_cache_control(worker/leaf_website/__init__.py) made the container answer everything a visitor's page loads withno-store: its document, state, event answers and attached images.SampleEndpointcopied its parent's two attributes (src/leaf/http.py), so a live sample's child page on leaf.page answeredno-storelike its parent.Cache-ControlPython captured on every saved response withprivate, no-store(worker/src/storage.ts). Those saved responses serve the acted-on page's document and state while the container sleeps. The Durable Object now serves Python's headers unchanged.The edge's own answers:
staticState, also used during a rollout) now saysno-cachewithVary: Leaf-Data-Version, Leaf-View-Revision, the request headers its body depends on, just as Python's state answer names its own. WithoutVary, a document Chrome loads from history could reuse a stored answer whose data was left out for another tab.no-store. Browsers don't store the answer to afetchPOST, so it protected nothing.no-storeon the rollout refusal (503 this release is still starting). It protects against a stored error, not a page's document, state or media: a history load reuses a stored answer without asking. In Chromium 156 with the back/forward cache off, Back showed a storedno-cache503 document again without a request, while ano-storeone was fetched again. Withoutno-store, the refusal could replace the page after the rollout ends.notes/browser-support.md("Page cache"),worker/README.md(saved state) and the private-state paragraph ofdocs/website.htmlnow describe the single policy and its cost.What the visitor gains, and the cost accepted
On Back, the page reappears at once with its scroll position, selection, focus and open disclosures, and the runtime catches up from there. Before this change, it loaded again, and Chrome or Firefox showed its state after about 100–180 ms. Attached images are also no longer fetched again on every load.
The cost, accepted by the maintainer: a visitor's comments, replies and images stay in the browser's disk cache after their session. Back shows them to whoever next uses that browser profile.
How Chrome decided
Measured in Playwright's full Chromium 156.0.8078.4 with its back/forward cache enabled. A
no-storedocument alone is now kept. Chrome drops it once a fetch from the page also gets ano-storeanswer, or once an HttpOnly cookie changes. Acting on a leaf.page page does both: the activation cookie is set, and the container answers the page's state reads. Ano-cachedocument was kept even when its fetches gotno-storeanswers or set cookies. That is why the edge's POST acknowledgements did not block the back/forward cache once the document saidno-cache.Tests
tests/process/website_server/test_routes.py: the website's document, state and an attached image now assert the shared policy. Onmainthe same assertions fail with'no-store' == 'no-cache'. The sample test's image upload is removed: it existed to check that the parent's policy reached the child, and that copy no longer exists.worker/test/storage.test.ts: a saved image is served with theCache-ControlPython captured.worker/test/index.test.ts: the published state answer saysno-cachewith itsVary. Both fail onmain:expected 'private, no-store'andexpected 'no-store'.pnpm run check:workerandpnpm run checkpass. Thewebsite_serverroute and saved-record tests, the local server's cache-header test, the sample, media and news tests intest_interact_server.py, andtest_a_page_loaded_from_history_reads_state_from_the_serverpass.leaf_website, run as the container runs it) on the built site. It openedheat-loss, chose an option, reloaded to get the private document, selected a paragraph, followed a link and pressed Back 5 times. With this branch, all 5 Backs restored the page:pageshow.persistedwas true and the selection was still there. Withmain's container code, all 5 reloaded, withMainResourceHasCacheControlNoStoreandJsNetworkRequestReceivedCacheControlNoStoreResource.wrangler dev. On this Mac, the local Worker's first request to a page container hung.leaf-dev verify-site website-workerhung the same way at its activation read, and the container logged no request. The PR'stestjob runs that verifier on Linux. Safari remains unverified.Closes #4024