Cache TOC for later usage in the case of cached file html #649
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #509.
How to reproduce
id
, e.g. https://docsify.js.org/#/plugins?id=full-text-searchExpecting:
But got:
Issue
Sub-sidebars are rendered using TOC of the file of current page.
The first time loading
plugins.md
, compiler compiles the markdown content and caches it [code ref 1].During the compiling process, TOC of this file is built [code ref 2].
this.toc
is then used bycompiler.subSidebar
to generate sub-sidebars.When navigating to other pages and back,
compiler.compile
loads html forplugins.md
from cache, which bypasses the step of compiling, which results in no TOC, which results in this issue - no sub-sidebars.Solution
Add cache for TOC, and use file names as keys to avoid unnecessarily storing whole file content in memory.
Other notes
While debugging this one, found out that SSR version has the same problem. #650
Haven't checked whether this PR fixes both or not.