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

Throw an error when mixing extract: true and classHashPrefix configuration options to avoid unsupported usage and bundle size bloat. #1724

Merged

Conversation

kylorhall-atlassian
Copy link
Collaborator

@kylorhall-atlassian kylorhall-atlassian commented Oct 15, 2024

What is this change?

Following #1717, throws an error when Parcel attempts to transform or Webpack's CompiledExtractPlugin is initialized with both extract: true and classHashPrefix being defined.

Why are we making this change?

To avoid unsupported usage and bundle size creep as adding 5 bytes to every class is not something we want to generally promote and instead classHashPrefix is only desired as a temporary workaround to avoid conflicts in scenarios where non-extraction is used.

How are we making this change?

Into the Parcel Transformer and Webpack Loader, the entrypoints where this configuration bleeds in. Technically this wasn't documented properly for @compiled/webpack-loader, so I adjusted it briefly, but kept the throw new Error in place to avoid this (as it would still be passed through, I'd gather).


PR checklist

  • NOT updated or added applicable tests — I don't think this is feasible without making a brand new fixture for each scenario.
  • Updated the documentation in website/ — Modified briefly, but I'm not sure it's worth documenting in full (this already isn't documented in full).
  • Review @guilhermehto's internal PR to validate it will work with this

…iguration options to avoid unsupported usage and bundle size bloat.
Copy link

changeset-bot bot commented Oct 15, 2024

🦋 Changeset detected

Latest commit: 035de35

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@compiled/parcel-transformer Minor
@compiled/webpack-loader Minor
@compiled/babel-plugin Patch
@compiled/parcel-config Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Oct 15, 2024

Deploy Preview for compiled-css-in-js ready!

Name Link
🔨 Latest commit 035de35
🔍 Latest deploy log https://app.netlify.com/sites/compiled-css-in-js/deploys/6711cbb670de5c000838e143
😎 Deploy Preview https://deploy-preview-1724--compiled-css-in-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +111 to +112
* Avoid mixing this with extraction as this may throw an error if combined with extraction
* or `extract: true` in Webpack loaders or Parcel tranformers.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This documentation isn't relevant, I don't think you can mix Babel + extraction elsewhere, but just covering my bases…

Comment on lines 112 to 117
// @ts-expect-error -- Make sure this config doesn't bleed in as it's passed through
if (options.classHashPrefix) {
throw new Error(
'`@compiled/webpack-loader.CompiledExtractPlugin` is mixing `extract: true` and `classHashPrefix` options, which will not supported and will result in bundle size bloat.'
);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've removed the config actually, so you can't do CompiledExtractPlugin({ classHashPrefix: … }), but kept the @ts-expect-error to document it in full (because it'd work without TS blocking you, I believe.

@@ -211,7 +211,6 @@ module.exports = {
`@compiled/webpack-loader` also accepts the following options. These are not used in the loader itself, but instead they are passed directly to the underlying `@compiled/babel-plugin`.

- `addComponentName`
- `classHashPrefix`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was actually on the wrong place, this says it works with @compiled/webpack-loader, but I'm pretty sure it only works with new CompiledExtractPlugin({…}). Could be wrong!

liamqma
liamqma previously approved these changes Oct 15, 2024
@@ -124,6 +124,12 @@ export default new Transformer<ParcelTransformerOpts>({
},

async transform({ asset, config, options }) {
if (config.extract && config.classHashPrefix) {
Copy link
Collaborator

@dddlr dddlr Oct 15, 2024

Choose a reason for hiding this comment

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

note that config.extract is currently ignored in non-production environments when using Parcel

(stylesheet extraction doesn't work in non-prod environments when using Parcel)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got it, this kind of might be the wrong thing in that case if there's no different configs…I'm not sure exactly, might wait to see the PR from @guilhermehto to see if this would blow up or not.

Comment on lines +111 to +117

// @ts-expect-error -- Make sure this config doesn't bleed in as it's passed through
if (options.classHashPrefix) {
throw new Error(
'`@compiled/webpack-loader.CompiledExtractPlugin` is mixing the `extract: true` and `classHashPrefix` options, which is not supported and will result in bundle size bloat.'
);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This may not work given the classHashPrefix is passed to the babel plugin isn't it? I'm a bit uncertain how this works to be frank!

@kylorhall-atlassian kylorhall-atlassian enabled auto-merge (squash) October 18, 2024 02:45
@kylorhall-atlassian kylorhall-atlassian merged commit c165531 into master Oct 18, 2024
13 checks passed
@kylorhall-atlassian kylorhall-atlassian deleted the kylorhall/throw-error-extract-classHashPrefix branch October 18, 2024 02:49
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.

4 participants