Open feichao93 opened 3 years ago
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!
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.
This cache makes it worse because the cache is written to disk, so even user restart webpack they may still get stale __docgenInfo.
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
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
webpackModule._source.node().sourceContents[webpackModule.userRequest]
can do the work, but I'm not sure whether it is the correct way to do so.
reproduce demo: https://github.com/shinima/temp-react-docgen-typescript-plugin-issue28
steps to reproduce and debug are listed in readme
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.
Thanks for the library, it's very helpful when developing a React component library doc site.
https://github.com/hipstersmoothie/react-docgen-typescript-plugin/blob/abe4c74f104212b1d32e7698eab3301fb2b8dbb6/src/plugin.ts#L99-L109
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.