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

Stale __docgenInfo generated due to cache #28

Open
feichao93 opened this issue Feb 18, 2021 · 7 comments
Open

Stale __docgenInfo generated due to cache #28

feichao93 opened this issue Feb 18, 2021 · 7 comments

Comments

@feichao93
Copy link

Thanks for the library, it's very helpful when developing a React component library doc site.

const hash = crypto
.createHash("sha1")
.update(webpackModule._source._value)
.digest("hex");
const cached = cache.getKey(hash);
if (cached) {
debugInclude(`Got cached docgen for "${webpackModule.request}"`);
webpackModule._source._value = cached;
return;
}

webpackModule._source._value seems to be the output of the ts-loader. So when user only edits the comments in a TS interface, webpackModule._source._value will keep same as before ( because the whole interface code is stripped by ts-loader) . In this case, the produced __docgenInfo will be incorrect, and the doc page which consumes __docgenInfo will display wrong interface comments.

@hipstersmoothie
Copy link
Owner

This is the same problem as this issue but the cache was introduced after this bug was seen. So i'm not sure it's the caching that is going wrong. If you comment out the caching code the problem can still be seen

Me and @ndelangen tried debugging this to no avail. If you place a console log here you can see that the docs get generated correctly, it just doesn't trigger webpack to reload.

If you can find a solution I will happily merge it!

@feichao93 feichao93 changed the title Incorrect __docgenInfo produced due to cache Stale __docgenInfo generated due to cache Feb 19, 2021
@feichao93
Copy link
Author

feichao93 commented Feb 19, 2021

I think the problem is at this line, here cached is stale since the original source code has been changed, though webpackModule._source._value keeps the same due to ts-loader.

In my own project, if I comment out cache-related code in the plugin, no stale __docgenInfo will be generated. I can provide a re-production repo later.

image

This cache makes it worse because the cache is written to disk, so even user restart webpack they may still get stale __docgenInfo.

@hipstersmoothie
Copy link
Owner

You if you could to ids a reproduction repo that would be great.

You could also try out 0.6.3 before I added the caching

@hipstersmoothie
Copy link
Owner

But yeah I could see how this would make the problem worse. Is there a way to get the original source value? That would make the cache better

@feichao93
Copy link
Author

webpackModule._source.node().sourceContents[webpackModule.userRequest] can do the work, but I'm not sure whether it is the correct way to do so.

image

@feichao93
Copy link
Author

feichao93 commented Feb 19, 2021

reproduce demo: https://github.com/shinima/temp-react-docgen-typescript-plugin-issue28

steps to reproduce and debug are listed in readme

@feichao93
Copy link
Author

feichao93 commented Feb 19, 2021

There are cases that the user edits some types.tsx / interfaces.tsx file which exports some base interfaces that the component extends. The __docgenInfo of the component should be updated even if the source code of component does not change. In such cases, cache is really hard to design/implement... 🤔

An option to disable the cache can be a workaround. I don't known there is a better way to handle this.

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

No branches or pull requests

2 participants