Repository navigation
perf(flame): keep the page cache when docu.json lists plugins - #491
Conversation
flame build skipped the page cache as soon as one plugin was configured (`&& !builder` in both page loops), so every docs page was re-rendered on every build. The bypass was the only guard against stale output: the page key only covers the MDX source, and nothing in the key covered plugin code. Add pluginsStamp() to the cache key material, folded into renderToolchainStamp(): a plugin package hashes as its version plus its built dist/, a local plugin as the file the runtime loads (extensionless specifiers and directory index files included), anything unresolvable as "missing". A plugin upgrade or rebuild now discards the cache and the bundle, so the bypass can go. BUILD_CACHE_VERSION goes to 10. Per-page hooks (transformFrontmatter to transformHtml) now run only for pages that are rendered again; onEnd still receives every page. The plugin docs and a changeset say so.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
ℹ️ One gap in the plugin fingerprint is worth closing before merge. Everything else looks sound.
Reviewed changes
Senior-mode review of the flame build cache change: plugin code now goes into the render stamp, so the page cache stays on in projects that configure plugins.
pluginsStamp()incache-key.ts: fingerprints eachdocu.jsonplugin. npm plugins use their version and builtdist/, local plugins hash the file the loader would pick, and unresolvable plugins become"missing". The stamp is folded into the memoizedrenderToolchainStamp()andBUILD_CACHE_VERSIONgoes up to 10.- Page loops in
build.ts/build.impl.ts: the&& !builderbypass is gone, so unchanged pages are skipped whether or not plugins are configured. - Docs + changeset: the Lifecycle diagram and prose say per-page hooks now run only for re-rendered pages.
onEndstill receives every page.
Assessment: READY WITH MINOR FIXES. One P2 finding (confidence 0.85, dimension: correctness):
- [P2]
cache-key.ts:193: plugins that only export animportcondition always fingerprint as"missing", so upgrading one leaves stale HTML. Details inline.
The remaining paths look correct to me. A change to onLoad output still reaches the bundle hash through the prepass, which sets assetsChanged and re-renders every page. The removed bypass guarded nothing besides the plugin-code gap that this stamp now covers. The PR description already lists the remaining limits: the clock, environment variables and files imported by a local plugin.
claude-opus-5-5 | 𝕏
pluginsStamp() resolved npm plugins with createRequire().resolve(), which only matches the require/node/default export conditions. A plugin whose exports map has only an `import` condition threw ERR_PACKAGE_PATH_NOT_EXPORTED, was skipped, and kept the stamp at "missing" across upgrades, so cached pages kept the old plugin's HTML. Find the package by walking up node_modules from the directory plugin-loader imports from (cache-key sits next to it in .docu/node and .docu/lib), like import() does. This does not depend on export conditions. The manifest stands in for the entry, since only dist/ is hashed. Adds a test with an import-only exports map.
There was a problem hiding this comment.
✅ No new issues found. The ESM-only plugin gap from the previous review is closed.
Reviewed changes
Senior-mode re-review of 7d1a5a7. This commit changes how pluginsStamp() finds npm plugin packages.
- Replaced
require.resolvelookup withfindInstalledPackage(): the new function walks upnode_modules/<name>/package.jsonfrompackagesFromand realpaths the match. It no longer depends onexportsconditions, so import-only plugins now fingerprint by version anddist/.packageFingerprintonly checks thatentryexists, so passing the manifest as the entry is safe. - Added a
packagesFromparameter, defaulting tocache-key's own directory:plugin-loader.tssits in the same directory in.docu/nodeand in the compiled.docu/lib(compile-liboutDir). Node realpaths module URLs, so under pnpm the walk covers the same directories as the loader'simport(specifier). - Added a regression test: it uses an import-only
exportspackage found from a nested directory and checks that the stamp changes on a version bump and on adist/edit. The existing cases now passpackagesFromexplicitly.
Assessment: READY. No P0–P2 findings.
claude-opus-5-5 | 𝕏

Summary
flame buildstopped using its page cache as soon asdocu.jsonlisted a plugin, so every docs page was re-rendered on every build. This PR adds the plugins to the cache key and removes that bypass. Unchanged pages are now skipped with or without plugins. A plugin upgrade, a rebuilt plugin, or an edited local plugin still re-renders every page.Why the cache was off with plugins
Both page loops (
build.tsfor Bun,build.impl.tsfor Node/Deno) only skipped a page when no plugin was configured:That bypass (added in #378) was the only guard against stale output. The page key covers only the MDX source, and the rest of the key material covers
docu.json(configStamp()), the framework sources, and the@docubook/*packages. Plugin code was in none of them. Sodocu.jsoncaught a plugin's options changing, but nothing caught an upgraded plugin package or an edited local plugin file.What changed
cache-key.ts: newpluginsStamp(), a fingerprint of every plugin indocu.json:@docubook/plugin-search-algolia)versionfrom itspackage.json+ hash of its builtdist/(reusesresolvePackages/packageFingerprintfromdev-watch.ts)./plugins/reading-time).ts,.tsx,.mts,.js,.mjs,.cjs, thenindex.ts/index.js/index.mjsin a directory, since the docs write local plugins without an extension"missing"(never throws;loadPluginsreports the real error)It is folded into
renderToolchainStamp(), whichreadCache()checks (meta.render) andhashMdxSources()hashes. When a plugin changes, the whole page cache is discarded and the client bundle is rebuilt.BUILD_CACHE_VERSIONgoes from 9 to 10, following the existing convention for new key material.build.ts,build.impl.ts: the&& !builderbypass is removed from both page loops.Docs: the plugin Lifecycle section in
plugins.mdxnow explains that the cache can skip a page.Changeset:
@docubook/flameminor.Behavior change for plugin authors
onLoadstill runs on every file, in the pre-pass that compiles the client bundle.transformFrontmatter, remark/rehype,injectHead,injectBody,transformHtml) now run only for pages that are rendered again.onEndstill receives every page (mdxFiles, not just the rendered ones), and still runs on every build.A plugin that collects data from per-page hooks to use in
onEndwill only see the re-rendered pages. A plugin whose output depends on anything outside its code anddocu.json(environment variables, remote APIs, the clock) will keep the HTML from the last render untilflame build --force. The first-party Algolia plugin uses onlyinjectHead(static per build) andonEnd, so neither case applies to it.Known limit: for a local plugin, only the plugin's own file is hashed, not the files it imports. After editing one of those, run
flame build --force. Ashortcut:comment in the code records this.Benchmark
Flame's own docs: 27 pages,
@docubook/plugin-search-algolia0.1.2, Bun, macOS, one machine. "Before" ismain. Page phase is theBuilt N pages (… ms)timing; total is the wholepnpm run build.touch)--forceThe page phase is ~9× faster when nothing changed. The rest of the total (startup, bundle, Tailwind, search index) is untouched. The saving grows with the page count, because before, every page was rendered on every build.
Plugin assets: verified intact
Every scenario started from an empty
.docu/dist. In each one, a checker confirmed:src/hrefin every HTML file points to a file that exists (flame CSS/JS/chunks);<head>, and its client module (assets/docsearch/client.js) exists;assets/docsearch/--forceHTML from scenarios 2, 3, 5, 7, and 8 is byte-identical to the clean full build across all 30 HTML files, ignoring the per-render CSP nonce. Why the assets stay intact:
onEnd, which runs every build. Scenario 3 shows a cached build restores deleted plugin assets.<meta>inside each page, so a cached page's nonce still matches its own scripts.dist/also re-rendered every page, and restoring it did the same.Test plan
pnpm exec vitest runinpackages/flame: 869/869 passedtsc --noEmit,oxlintcleancache-key.test.ts:pluginsStampchanges on a package version bump, adist/change, a local file edit, an extensionless.tslocal plugin edit, and a directoryindex.jsedit, and does not throw for unresolvable plugins.h.update("plugins\0").update(pluginsStamp())call is present, and the!builderbypass is gone from both build files.build.impl.tsgets the same two-line change), plugins other than Algolia, and whetherpluginsStampresolves the same plugin copy asloadPluginswhen flame is installed from npm in a user project (it does in this monorepo)