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

fix(webpack): pass dependencies to cached css files #1080

Merged
merged 1 commit into from
Oct 17, 2022

Conversation

jneander
Copy link
Contributor

@jneander jneander commented Oct 13, 2022

When webpack is run with --watch or with webpack-dev-server, the generated css output will not be updated when dependencies imported into Linaria JavaScript source files, causing the resulting output to be stale.

The changes to the ICache interfaces are backward-compatible to avoid breaking any external implementations provided to the webpack builders using the prior versions of the interfaces.

Motivation

This addresses #1077.

Summary

Webpack allows adding dependencies to modules. Since the *.linaria.js and *.linaria.css files need to be in sync in order to generate the correct changes in webpack's watch mode, the css loader needs to have access to that dependency list so that it can tell webpack when it needs to change. The logical place for this was in the cache provider. But rather than update the cached data type and break the contract on the api, I opted to add an optional set of methods which implementers don't need to worry about unless they need to address this same issue using their own cache implementation.

These changes apply to both @linaria/webpack4-loader and @linaria/webpack5-loader.

Test plan

The proof-of-concept for this fix came from hacking the @linaria/webpack5-loader installation used in another project. When the changes are applied to the installation, the desired behavior is realized. The intended behavior has been verified using a demo project for both the webpack 4 and webpack 5 versions.

To verify the behavior, follow the test plan in the example repo linked in #1077. At step 5, the behavior described will be corrected after these changes are applied.

@Anber
Copy link
Collaborator

Anber commented Oct 14, 2022

@jneander amazing! Thank you!

May I ask you to run pnpm changeset and briefly describe the changes? Probably, I should add a bot which can do it right from the comments 🤔

@jneander jneander force-pushed the watched-css-dependencies branch from 666245c to b97495d Compare October 15, 2022 14:22
When webpack is run with `--watch` or with `webpack-dev-server`, the
generated css output will not be updated when dependencies imported into
Linaria JavaScript source files, causing the resulting output to be
stale.

The changes to the `ICache` interfaces are backward-compatible to avoid
breaking any external implementations provided to the webpack builders
using the prior versions of the interfaces.
@jneander jneander force-pushed the watched-css-dependencies branch from b97495d to 98422a2 Compare October 15, 2022 14:34
@jneander
Copy link
Contributor Author

@Anber Of course! Apologies for missing that step. 😞 I've added that with the latest changes. Do let me know if there's anything you'd like changed.

Good news for the webpack 4 version: The types in DefinitelyTyped have been updated! So I went ahead and reincorporated the changes into the @linaria/webpack4-loader package and verified the behavior in a demo project. I've updated the PR body to reflect that.

@Anber Anber merged commit 2906ec1 into callstack:master Oct 17, 2022
@jneander
Copy link
Contributor Author

Thank you, @Anber! 🎉

@Anber
Copy link
Collaborator

Anber commented Oct 20, 2022

@all-contributors please add @jneander for code

@allcontributors
Copy link
Contributor

@Anber

I've put up a pull request to add @jneander! 🎉

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