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

[Bug] Local version of webpack-virtual-modules in next-with-linaria #168

Closed
ramblehead opened this issue Aug 25, 2023 · 3 comments
Closed

Comments

@ramblehead
Copy link

ramblehead commented Aug 25, 2023

Hi! Apologies for a bit unconventional bug report.

I came to this repository when trying to debug the following issue in next-with-linaria project:
dlehmhus/next-with-linaria#19

The author of next-with-linaria @dlehmhus decided to include a patched version of webpack-virtual-modules into their repository. The patch is the following:

https://github.com/dlehmhus/next-with-linaria/blob/62f4603fa8ce8d723749152615ec6c684b3cd45a/src/plugins/webpack-virtual-modules/index.ts#L120

I do not fully understand how webpack-virtual-modules work and cannot tell if this patch is legitimate. If it is legitimate, would it be possible to add an optional parameter to VirtualModulesPlugin constructor or writeModule member function to switch between "throw new Error(Plugin has not been initialized);" and next-with-linaria patch behaviours. So, the author of next-with-linaria can just add webpack-virtual-modules to the packages instead of including the whole source code?

Also, I would be grateful if someone more knowledgeable could take a look at the next-with-linaria issue 19 mentioned above. It is quite puzzling to me why removing the following code in webpack-virtual-modules fixes that issue (at least from the user interface point of view):

setData(getReadDirBackend(finalInputFileSystem), dir, createWebpackData(files));

@larixer
Copy link
Member

larixer commented Aug 25, 2023

From the description I didn't understand neither why is the webpack-virtual-modules have bug nor where is the bug in the behavior or how to reproduce it? It is on the reporter to prove that the project has bug and submit a valid minimal reproducible bug report.

@larixer larixer closed this as completed Aug 25, 2023
@ramblehead
Copy link
Author

@larixer thank you for the quick response! I apologised that this report is a bit unconventional - it is about another repository that is using webpack-virtual-modules and including a patched copy of webpack-virtual-modules source rather than including it as a package. That is the reason the steps to reproduce the bug are described in my original report dlehmhus/next-with-linaria#19

I would like to apologise again for not being clear. I have created two demo repositories using next.js 13 and yarn 3 zero install to be able to reproduce this issue as easily as possible:

https://github.com/ramblehead/nextjs-tw-linaria
https://github.com/ramblehead/nextjs-app-tw-linaria

When running yarn dev from the above nextjs-tw-linaria repository with pages next.js router, everything works as expected, such as:

  • Remove backgroundImage from nextjs-tw-linaria/tailwind.config.ts config.
  • Change body.background in nextjs-tw-linaria/src/styles/globals.css.
  • Change background-color in nextjs-tw-linaria/src/components/view/linaria-button.ts.

All above changes are reflected via hot reload as expected and linaria updates are using webpack-virtual-modules under the hood.

When running yarn dev from the second repository nextjs-app-tw-linaria with app next.js router, hot reload only works with Linaria components, such as:

  • Change background-color in nextjs-app-tw-linaria/src/components/view/linaria-button.ts

Changes to globals.css and Tailwind files are no longer hot-reloaded by next.js. I.e. webpack-virtual-modules copy that is included in nextjs-tw-linaria works as expected while next.js 13 hot reloading for other css files stops working.

Please, let me know if any further information is required to reproduce this issue or if this is a wrong place to report it.

@larixer
Copy link
Member

larixer commented Aug 25, 2023

@ramblehead I understand. For the bug report to be reproducible is a necessary requirement, but not the only requirement. There is another requirement, that the reproduction should be minimal, and not in the sense of minimal number of commands to execute, but rather it should involve minimal number of components involved and including next-with-linaria into the issue makes it no longer minimal. I cannot delve into specifics of each project that uses virtual modules, it is too time consuming, hence the issues here should be about webpack-virtual-modules behavior only and should be minimal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants