Skip to content

fix(embed): scope cached includes to their page context - #2820

Merged
sy-records merged 2 commits into
docsifyjs:developfrom
xu91102:fix/embed-cache-route
Nov 14, 2026
Merged

sy-records merged 2 commits into
docsifyjs:developfrom
xu91102:fix/embed-cache-route

Conversation

@xu91102

@xu91102 xu91102 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Pages in different directories can display the wrong embedded file when their Markdown is identical. For example, both /first/ and /second/ can contain [snippet](snippet.js ':include :type=code'), while each directory has its own snippet.js. Visiting the first page and then the second currently keeps displaying the first directory's code.

The prerender cache is keyed only by raw Markdown, even though relative include resolution depends on the content base and current route. Include those two values in the cache key. The browser regression navigates first → second → first and checks the actual rendered code each time.

Related issue, if any:

Reproduced on develop at d823dbe51c1b2dea4c2091e2b952ded0d1e16616; no matching open fix found.

What kind of change does this PR introduce?

  • Bugfix

For any code change,

  • Related documentation has been updated, if needed (no public API change)
  • Related tests have been added or updated

Does this PR introduce a breaking change?

  • No

Validation

  • The browser regression failed before the fix: the second page rendered the first page's snippet. It passes after the fix, including navigation back to the first page.
  • npm run test:e2e:chromium -- test/e2e/embed.test.js --workers=1 --reporter=line: passed.
  • npm run test:jest -- --runInBand: 128 tests and 46 snapshots passed.
  • npm run build, npm run lint, npm run typecheck, and git diff --check: passed.
  • Independent read-only review: no required changes.

Browser coverage: Chromium via Playwright; Firefox, WebKit, and unrelated E2E suites were not run locally.

Developed with assistance from OpenAI Codex; regression and fix validated locally.

@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Docsify Team on Vercel.

A member of the Team first needs to authorize it.

@sy-records
sy-records force-pushed the fix/embed-cache-route branch from 431a9b8 to 47ba462 Compare October 16, 2026 03:58
@sy-records
sy-records force-pushed the fix/embed-cache-route branch 3 times, most recently from cb56726 to 795936d Compare October 27, 2026 02:52
@sy-records
sy-records force-pushed the fix/embed-cache-route branch from 795936d to 4ecc34e Compare October 27, 2026 03:19

@sy-records sy-records left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I haven't been able to reproduce the issue. Could you set up a sandbox to help me reproduce it?

@xu91102

xu91102 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking, @sy-records. Here is a runnable StackBlitz reproduction. In the preview, click Run first → second → first. Both routes use byte-identical Markdown and different sibling snippet.js files. The button navigates in the same page without a reload.

Browser visit Develop 91c923a PR 4ecc34e
/first/ first first
/second/ first (stale) second
/first/ first first

I built both Docsify bundles from those commits and reproduced the same result in Chromium, locally and in the StackBlitz preview. For local use, download the fixture ZIP, extract it, run npm start in that directory, and open http://localhost:8000. No dependency installation is needed.

Chromium reproduction showing the stale include on the second route

@sy-records

Copy link
Copy Markdown
Member

Please use CodeSandbox; it seems your example is a usage issue.

@xu91102

xu91102 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

I added a minimal reproduction for the CodeSandbox request using default Docsify settings and ordinary hash links. Both Markdown pages use the documented code-include syntax and each has a different sibling snippet.js.

Import xu91102/docsify branch repro-2820 into CodeSandbox. The fixture at f4894e6 includes a task to start the port 8000 preview. CodeSandbox's security check blocked my browser, so I could not verify its hosted preview.

To run the same fixture locally, download the ZIP, extract it, and run npm start with no install step. Open /fixtures/before.html#/first/ in the port 8000 preview and click Second, then First without reloading. Repeat with /fixtures/after.html#/first/.

Chromium showed first → first → first on develop 91c923a and first → second → first on PR head 4ecc34e. The screenshots show the code block after clicking Second.

Develop 91c923a on the second route still displays first

PR 4ecc34e on the second route displays second

@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
docsify-preview Ready Ready Preview Nov 13, 2026 4:49am UTC

@sy-records sy-records left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, the reason it couldn't be reproduced earlier was because there was a hook.beforeEach . Now it can be reproduced.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The review identifies no active issues with the directory-scoped embed cache change.

No open issues 🎉

What changed in this PR

Fixes Docsify’s embed cache so pages with identical Markdown display relative includes from the correct content directory.

Changes:

  • Scope cached tokens by resolved content directory and raw Markdown.
  • Add unit coverage for cache reuse within a directory and separation across directories and content bases.
  • Add a browser regression checking rendered snippets during first → second → first navigation.
File Description
test/​unit/​embed-cache.test.js Verifies context-specific caching and reuse.
test/​e2e/​embed.test.js Checks relative include content across page navigation.
src/​core/​render/​embed.js Keys cached tokens by content directory and Markdown.

Review effort: Balanced

@sy-records
sy-records merged commit 0e0cd50 into docsifyjs:develop Nov 14, 2026
8 checks passed

This branch was successfully deployed

1 active deployment
Preview — 923280a1 Deployed Nov 13, 2026 by vercel[bot]
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.

3 participants