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

Not rerender when code snippet file changes #1309

Closed
1 task done
shigma opened this issue Feb 18, 2019 · 6 comments
Closed
1 task done

Not rerender when code snippet file changes #1309

shigma opened this issue Feb 18, 2019 · 6 comments
Labels
type: enhancement Request to enhance an existing feature

Comments

@shigma
Copy link
Collaborator

shigma commented Feb 18, 2019

  • I confirm that this is a issue rather than a question.

Bug report

Version

1.0.0-alpha.39

Steps to reproduce

The issue is found by @jiaming743 in #1297. Thanks!

Suppose we have two files, foo.js and foo.md.

foo.js

export default {
    // this is a test file
}

foo.md

<<< @/foo.js

What is expected?

When updating foo.js, foo.html will automatically rerender.

What is actually happening?

After updating foo.js, foo.html does not changes.

Other relevant information

  • Your OS: Windows
  • Node.js version: v10.12.0
  • Browser version: N/A
  • Is this a global or local install? Local
  • Which package manager did you use for the install? Yarn
@shigma
Copy link
Collaborator Author

shigma commented Feb 18, 2019

The problem is we use cache in markdown-loader:

https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/markdown-loader/index.js#L36

In that case, changes in code snippets will not be able to be detected even if we add them as dependencies.

@ulivz ulivz added the type: enhancement Request to enhance an existing feature label Feb 18, 2019
@shigma
Copy link
Collaborator Author

shigma commented Feb 18, 2019

@ulivz What do you mean by:

https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/markdown-loader/index.js#L30-L32

Can we only cache the markdown tokens and do the rendering repetitively?

@BuptStEve
Copy link
Contributor

BuptStEve commented Feb 18, 2019

I hava a plan.

  • markdown-loader index.js
  // const cached = cache.get(key)
  // if (cached && (isProd || /\?vue/.test(this.resourceQuery))) {
  //   return cached
  // }

  ...

  // the render method has been augmented to allow plugins to
  // register data during render
  const {
    html,
    data: { hoistedTags, links, deps },
    dataBlockString
  } = markdown.render(content, {
    frontmatter: frontmatter.data,
    relPath: path.relative(sourceDir, file)
  })

  deps.forEach(this.addDependency) // <-- add deps for webpack
  • markdown lib/snippet.js
    md.$data = md.$data || {}
    md.$data.deps = md.$data.deps || []
    md.$data.deps.push(filename) // <-- add dep
  • markdown index.js
module.exports.dataReturnable = function dataReturnable (md) {
  // override render to allow custom plugins return data
  const render = md.render
  md.render = (...args) => {
    md.$data = md.$data || {} // <-- markdown-it plugins can pass deps via md.$data
    
    ...
  }
}

deps

@ulivz what do you think?

@shigma
Copy link
Collaborator Author

shigma commented Feb 19, 2019

@BuptStEve
Working out a simple solution is not difficult, but actually we should make sure to take advantage of lru cache as far as possible. Your solution will increase the rendering time.

@BuptStEve
Copy link
Contributor

@BuptStEve
Working out a simple solution is not difficult, but actually we should make sure to take advantage of lru cache as far as possible. Your solution will increase the rendering time.

Yeah, it's just a simple and naive solution. Any better ideas?

@shigma
Copy link
Collaborator Author

shigma commented Feb 19, 2019

My idea is to separate md.render into two parts: md.parse and md.renderer.render.

Every part will has cache with it, which will not only solve the problem but improve performance for general situations as well. I will open a pr later to clarify some technical details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Request to enhance an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants