Skip to content

fix(flame): rebuild pages and bundle when a @docubook package changes - #437

Merged
gitfromwildan merged 1 commit into
mainfrom
fix/flame-bundle-cache-deps
Oct 31, 2026
Merged

gitfromwildan merged 1 commit into
mainfrom
fix/flame-bundle-cache-deps

Conversation

@gitfromwildan

Copy link
Copy Markdown
Member

Summary

flame build reused cached pages and the cached client bundle after a @docubook/* package it renders with had changed. Upgrading @docubook/markdown (for example to pick up #435) without editing any MDX kept serving HTML and JavaScript built from the previous version until --force. This PR adds a fingerprint of the built sibling packages to the cache key, so a package change rebuilds what it affects and an unchanged build stays fully cached.

Follow-up to #435, listed there under "Out of scope".

Why

What the cache keyed on

Cache slot Key before this PR Rendered from
Pages (.docu/build-cache.json per file) MDX source (mtime, then hash) MDX and @docubook/markdown, ui-react, core via SSR
Client bundle (__bundle__) hashMdxSources(compiled MDX, cssBundleStamp()) compiled MDX and the same packages
Whole cache (__meta__) cache version, runtime, renderToolchainStamp() (flame's own render sources) —

None of these keys covered the packages' code. cssBundleStamp() already followed @docubook/markdown/styles.css, but not the JavaScript.

Reproduction

With a warm cache in this repo, I added a data-repro attribute to role: "note" in packages/markdown/dist/components/Callout.js and ran flame build:

✓ Client bundle compiled (4ms)
✓ Built 0 pages (27 cached)

/docs/components/callout still had 0 of its 7 callouts with the attribute, and the client bundle did not contain it either. In a user project, the same thing happens after npm update @docubook/markdown, because .docu/build-cache.json lives in the project and survives upgrades.

Changes

  • .docu/node/dev-watch.ts: resolvePackages() is split out of resolveWorkspacePackages(). It resolves the copies flame actually loads, whether workspace-linked or installed under node_modules. resolveWorkspacePackages() is now that list without installed copies, so the dev watcher behaves exactly as before.
  • .docu/node/cache-key.ts:
    • packagesStamp() hashes every WATCHED_PACKAGES entry (core, markdown, ui-react, themes-colors) with the dev watcher's existing packageFingerprint(), which covers the JS and CSS in dist/ plus a root styles.css. A package whose entry is missing (mid-rebuild) is recorded as missing.
    • renderToolchainStamp() folds in packagesStamp(). That stamp already guards the whole cache through __meta__.render and is part of hashMdxSources(), so one change invalidates both the pages and the bundle.
    • BUILD_CACHE_VERSION goes from 7 to 8, with a v8 note.
  • .github/pullfrog-modes.md: cache version notes updated to v8, and the built packages added to the listed cache keys.
  • .changeset/flame-cache-sibling-packages.md: @docubook/flame patch.

The stamp hashes built output rather than versions. A workspace rebuild has no version bump, while an installed copy keeps the same content for as long as its version stays put.

Verification

  • Bun (bun .docu/node/build.ts), sequence on a warm cache:

    Step Pages Client bundle Marker in callout.html / bundle
    v7 cache on disk 27 built (0 cached) rebuilt 0 / 0
    nothing changed 0 built (27 cached) reused 0 / 0
    markdown dist edited 27 built (0 cached) rebuilt 7 / 1
    nothing changed 0 built (27 cached) reused 7 / 1
    markdown rebuilt 27 built (0 cached) rebuilt 0 / 0
  • Node (FLAME_RUNTIME=node node bin/cli.js build after compile:lib): same results. Cached when nothing changed, rebuilt with the marker after the edit, rebuilt without it after restoring.

  • Cost: fingerprinting the four packages (about 110 KB of JS and CSS) takes about 2.5 ms, once per build process (the result is memoized with the render stamp).

  • New tests:

    • resolvePackages keeps installed copies and skips unresolvable names.
    • packagesStamp follows content in an installed layout, including nested dist/ files and a missing entry, is stable across identical rewrites, and covers all four sibling packages in this monorepo.
  • pnpm lint, pnpm typecheck and pnpm test pass (1,128 tests). pnpm build --force and pnpm test:browser-smoke pass.

Impact

  • Existing projects: the first build after upgrading flame discards .docu/build-cache.json once, because of the version bump. After that, builds stay cached until an MDX file, a stylesheet, flame itself, or a @docubook/* package changes.
  • Monorepo development: rebuilding a sibling package now invalidates flame's build cache. flame dev already restarted on such rebuilds (fix(flame): restart the dev server when a workspace package rebuilds #427).

The build cache keyed pages on their MDX source and the client bundle
on the compiled MDX plus the stylesheet stamp. Both are rendered from
the built @docubook/core, markdown, ui-react and themes-colors
packages, but no key covered them. Upgrading one of them, or
rebuilding it in this monorepo, kept every page a cache hit and reused
the old client bundle until --force. Editing markdown's dist left the
seven callouts on /docs/components/callout and the client bundle on
the previous code.

- dev-watch: split resolvePackages() out of resolveWorkspacePackages().
  It resolves the copies flame loads, workspace-linked or installed.
  The dev watcher still skips installed copies
- cache-key: packagesStamp() hashes each package's built dist/ JS and
  CSS plus styles.css with the dev watcher's packageFingerprint().
  renderToolchainStamp() folds it in, so a change discards the whole
  cache through __meta__.render and changes the bundle hash
- BUILD_CACHE_VERSION 7 -> 8, also noted in .github/pullfrog-modes.md

Hashing the four packages costs about 2.5 ms once per build. On Bun
and on Node (.docu/lib), an unchanged rebuild still reports 27 of 27
pages cached. Editing markdown's dist now rebuilds all pages and the
bundle, and restoring it rebuilds them again.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docu Ignored Ignored Preview Oct 31, 2026 5:19am UTC

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

I reviewed this in senior mode because it touches the flame build pipeline. It adds a fingerprint of the built sibling @docubook/* packages to flame's build cache key.

  • resolvePackages() split: dev-watch.ts now resolves both workspace-linked and installed copies. resolveWorkspacePackages() is that list with node_modules copies filtered out, so the dev watcher behaves exactly as before.
  • packagesStamp() in the render stamp: cache-key.ts hashes each WATCHED_PACKAGES entry with the existing packageFingerprint() and folds the result into the memoized renderToolchainStamp(). That one change reaches both __meta__.render (pages) and hashMdxSources() (client bundle).
  • Cache version bump: BUILD_CACHE_VERSION goes from 7 to 8. The PR also adds a @docubook/flame patch changeset and updates the cache notes in .github/pullfrog-modes.md.

Things I checked:

  • Every package resolves: all four packages expose a default condition on exports["."], so createRequire().resolve() finds each of them. None is silently skipped.
  • themes-colors JSON is covered: its themes/*.json and syntax/*.json presets are imported by src/registry.ts and inlined into dist/. The fingerprint only reads dist/, but it still covers them.
  • Tests pass: cache-key.test.ts, dev-watch.test.ts and base-path.test.ts (161 tests) pass under Node after building flame's workspace dependencies.

Overall: READY. There are no findings and no top priorities.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@gitfromwildan
gitfromwildan merged commit 8a8f28e into main Oct 31, 2026
16 checks passed
@gitfromwildan
gitfromwildan deleted the fix/flame-bundle-cache-deps branch October 31, 2026 05:22
@github-actions github-actions Bot mentioned this pull request Oct 31, 2026
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