ReviewOS

also looking at this

stacks/stx

fix(serve): dev no-store caching + nested dynamic route regex

#1731
Merged glennmichael123 wants to merge fix/serve-cache-and-nested-routes into main
2 files +120 -35
9 days ago

Summary

Two dev-server correctness fixes in packages/bun-plugin/src/serve.ts. Bug reports tracked on the framework repo: stacksjs/stacks#1926 and stacksjs/stacks#1927.

stacksjs/stacks#1926 — dev mode emits no-cache (should be no-store)

  • 8 response sites set Cache-Control: no-cache. That means "revalidate before reuse", not "don't store" — and with no ETag/Last-Modified, Chrome/Safari heuristically reused stale bodies, so edit→save→reload sometimes showed ghost output. Swapped all 8 to no-store. The SSE stream's no-cache, no-transform is intentionally untouched (no static body to cache).
  • Companion: the rendered-HTML cache in processTemplate() is gated off (ENABLE_HTML_CACHE = false). templateSignatureFresh compares dependency mtimes, but transitive @includes sometimes weren't registered into the dependency set, so editing a deeply-included partial intermittently served stale HTML. The dev server should be source-of-truth every request; a fresh render (~50ms) is worth the correctness. Infra kept behind the flag to re-enable once dep-tracking is closed.

stacksjs/stacks#1927 — nested dynamic routes 404 on hard reload

  • judges/[id]/profile/index.stx produced ^judges/([^/]+)/profile/index$, which never matched judges/35/profile. The /index-stripped variant was already pushed inline; this extracts the regex-set construction into an exported buildDynamicRouteRegexes(fileRouteBase) (behavior identical) so it's unit-testable, and adds 10 tests (single-segment, nested, pages/-prefixed, capture-group, and back-compat for the index-included URL).

Note on stacksjs/stacks#1928

The sibling issue (_handleStxLoad only scanning the SPA container) is already fixed in current main — signals.ts walks document.body.querySelectorAll('[data-stx-scope]') at both the bind and mount loops (landed under #1697). No code change needed.

Test plan

  • packages/bun-plugin/test/dynamic-routes.test.ts — 10 new tests, all green
  • existing serve.test.ts — 6/6 green
  • no-store count = 8; SSE no-cache, no-transform preserved
  • maintainer: confirm disabling the dev htmlCache outright (vs. fixing transitive-include dep tracking) is the preferred call

🤖 Generated with Claude Code

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

Sign in to comment on this pull request.