Skip to content

Re-render only pages affected by header, footer and navigation edits, serve stale dev pages fresh. - #9

Merged
koculu merged 1 commit into
mainfrom
targeted-dev-rerenders
Oct 4, 2026
Merged

koculu merged 1 commit into
mainfrom
targeted-dev-rerenders

Conversation

@koculu

@koculu koculu commented Oct 4, 2026

Copy link
Copy Markdown
Member

Summary

Editing a header, footer or navigation file in serve now re-renders only the pages it affects, and the browser always gets the fresh page on reload. Previously, a header or footer edit threw away the builder and rendered every page. After that, the dev server could keep showing stale pages.

Changes

Header and footer edits no longer rebuild everything

An edit, addition or deletion of a header.mdx or footer.mdx recompiles the partials and marks only the pages whose nearest header or footer HTML actually changed. Editing guides/header.mdx touches guides/ pages, not components/, and not a subfolder with its own header. A root header still affects every page.

Navigation marks pages only when it changes

  • Content edits (navigation on) used to mark every page on every save. Navigation is now rebuilt and compared as data, so a body edit renders just that page; a title change marks the pages that show it.
  • _nav.json edits used to re-render every page right away. They now mark pages only if navigation changed, and a formatting-only edit costs nothing.

Stale pages render before they're served

The dev server used to answer with the old HTML, re-render in the background, then send a page-rendered event. That event usually arrived while the browser was still loading the old page, before its live-reload connection reopened, so it was lost and the stale page stayed. A page marked for re-rendering now renders before the response, so one reload shows the change. The background-render path and the page-rendered event are removed.

Requests use the current builder

The request handler held the first builder forever. After any full rebuild, changes went to the new builder while requests asked the old one, so stale pages were never re-rendered on request. Requests now read the current builder.

Live reload for marked pages

IncrementalBuildResult gains markedPages, and the dev server reloads the browser when pages were marked even though none rendered yet.

Test temp folders

The ts-ssg tests that bundle scripts need the repository's node_modules, so they create temp folders inside the repo. Those folders now go under .tmp/ through a shared makeRepoTempDir helper, instead of .tmp-* folders in the repo root.

Unchanged, deliberately

  • siteConfig.json edits still trigger a full rebuild; config shapes every output.
  • Adding or removing a page or asset still marks every page, since any content URL may resolve differently.
  • A failed incremental update still falls back to a full rebuild.

Docs

incremental.md is rewritten to match the code, which it no longer described. The README's dev-mode list notes that affected pages re-render on their next request.

Testing

  • Dev server: a new test starts a real server, edits guides/header.mdx, waits for the live-reload signal, then makes one request and asserts it shows the new header. It fails against the old serve-stale behavior.
  • Incremental: new tests cover:
    • a folder header edit, including a subfolder with its own header;
    • adding and removing a folder header;
    • a root footer edit;
    • body edits versus title edits under navigation;
    • _nav.json formatting-only versus reordering edits.
  • The ts-ssg suite passes, and Biome and TypeScript 7 are clean. Header edits were also checked by hand on the purestack.studio dev server.

@koculu
koculu merged commit f74becd into main Oct 4, 2026
2 checks passed
@koculu
koculu deleted the targeted-dev-rerenders branch October 4, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant