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: avoid empty CSS imports #289

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented Dec 6, 2022

Fixes #266. More details in #266 (comment).

Our Babel plugin that strips runtime also returns a set of CSS rules in its metadata. Before this PR it always returned at least an empty object. Because of this the check below didn't work:

As the check was passing always we were creating invalid imports for files that contain __styles as a string. Files like that were processed => got empty set of CSS rules => created an invalid import => crashed build.

@github-actions
Copy link

github-actions bot commented Dec 6, 2022

📊 Bundle size report

🤖 This report was generated against 1289343d950319f48888cfe70c1c84af066f08db

@layershifter layershifter marked this pull request as ready for review December 6, 2022 15:35
@layershifter layershifter requested a review from a team as a code owner December 6, 2022 15:35
@@ -0,0 +1 @@
export const foo = '__styles';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it make more sense to have better regex ? like __styles()? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this loader targets node_modules and needs to process thousands files in real projects, so if will put a regex in the hot path I believe that it will be a bottleneck.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps some kind of sliding window algorithm might be able to do the same thing while still being faster than Regex, especially you know how the call starts and terminates 🤔

but I guess handling empty buckets is a better gate

@layershifter layershifter merged commit 7d3fa72 into microsoft:main Dec 9, 2022
@layershifter layershifter deleted the fix/empty-css branch December 9, 2022 10:44
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.

extraction-plugin: support for appDir in NextJS 13
2 participants