ReviewOS

also looking at this

stacks/stx

fix(serve): render every request when cache is false

#2106
Open mkantautas wants to merge fix/serve-cache-option into main
2 files +109 -4
8 days ago

Problem

The programmatic serve() never reads the cache option. Its page and markdown caches are always on, so cache: false in the stx options or in stx.config.ts changes nothing: a page whose <script server> computes something per request keeps returning its first render, and a page whose partial changes keeps serving the old render until the page file itself changes.

Fix

With cache: false, serve() neither reads nor writes those caches, so every request renders. The option is read on every use, because serve() refreshes its options in place when a layered config changes. With cache on (the default) nothing changes. Invalidating a cached page when one of its partials or layouts changes is a separate problem and not part of this PR.

Tests

Four cases in test/serve/serve-cache-option.test.ts against a real serve(): every request renders, a changed partial shows up on the next request, the default still caches, and a config reload that switches cache from false to true and back is followed. On main the three cache: false cases fail, for example:

Expected: 2
Received: 1

bun run build, bun run smoke:install, bun run typecheck, bun run lint and bun run format:check pass, and bun test packages examples --max-concurrency=1 has no new failures compared with main (the tests failing on both need a browser or other parts of the environment I don't have).

2 changed files on the files tab, with 0 review threads.

Sign in to comment on this pull request.