Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache TOC for later usage in the case of cached file html #649

Merged
merged 1 commit into from
Oct 23, 2018

Conversation

cheng-kang
Copy link
Contributor

@cheng-kang cheng-kang commented Oct 18, 2018

Closes #509.

How to reproduce

  1. Open any page with id, e.g. https://docsify.js.org/#/plugins?id=full-text-search
  2. Navigate (from sidebar) to another page, e.g. http://127.0.0.1:3000/#/write-a-plugin
  3. Navigate (from sidebar) to the previous page, https://docsify.js.org/#/plugins

Expecting:
screenshot 2018-10-18 at 22 37 17

But got:
screenshot 2018-10-18 at 22 38 15

Issue

Use plugins page as an example

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 by compiler.subSidebar to generate sub-sidebars.

When navigating to other pages and back, compiler.compile loads html for plugins.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.

@QingWei-Li QingWei-Li merged commit 9e86017 into docsifyjs:master Oct 23, 2018
@QingWei-Li
Copy link
Member

Good job

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.

2 participants