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

[WIP] Allow external scoping #294

Closed
wants to merge 1 commit into from
Closed

Conversation

jonathantneal
Copy link
Contributor

Changes

  • Provides short path to fixing CSS parsing issues.
  • Provides short path to supporting container queries.
  • This allows external style scoping with an externalScoping flag.
  • Passes transformOptions to preprocessStyle, which should allow PostCSS to apply the styling.

Testing

help needed

Docs

help needed

@changeset-bot
Copy link

changeset-bot bot commented Feb 16, 2022

⚠️ No Changeset found

Latest commit: 2c3513c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@jonathantneal jonathantneal marked this pull request as draft February 17, 2022 14:10
@jonathantneal jonathantneal changed the title Allow external scoping [WIP] Allow external scoping Feb 17, 2022
StaticExtraction bool
}

func Transform(doc *astro.Node, opts TransformOptions) *astro.Node {
shouldScope := len(doc.Styles) > 0 && ScopeStyle(doc.Styles, opts)
shouldScope := opts.ExternalScoping || len(doc.Styles) > 0 && ScopeStyle(doc.Styles, opts)
Copy link
Contributor

Choose a reason for hiding this comment

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

The shouldScope variable is used to determine if the scoped class name should be added to elements. We don't want this to always be true, because some components do not need the elements to have a scoped class name.

Components that do not have any <style>s or only have <style global> do not need the scoped class name. So in this case I think it makes sense for ScopeStyle to still run, but take opts.ExternalScoping into account for whether not not the CSS should be scoped.

@@ -129,7 +135,7 @@ func preprocessStyle(i int, style *astro.Node, transformOptions transform.Transf
return
}
attrs := wasm_utils.GetAttrs(style)
data, _ := wasm_utils.Await(transformOptions.PreprocessStyle.(js.Value).Invoke(style.FirstChild.Data, attrs))
data, _ := wasm_utils.Await(transformOptions.PreprocessStyle.(js.Value).Invoke(style.FirstChild.Data, attrs, transformOptions))
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed? I think that ProcessStyle has access to all of these options on the JS side anyways. Is there something that it needs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so. This was to have the object containing the hash value (e.g. astro-hash1d2c3b4a).

Copy link
Contributor

Choose a reason for hiding this comment

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

We talked about this, make sense.

@natemoo-re
Copy link
Member

@jonathantneal I'm still tracking this, just FYI. I really want to unblock this and allow power users to bring their own scoping.

@natemoo-re
Copy link
Member

I dug into this over the weekend!

While this is definitely one possible route we could take to unblock modern CSS features, the best fix would be to use a better CSS parser that supports all of the features we need out of the box. This PR would mean users need to bring their own logic for scoping, which I can see being a pain.

I just opened a PR to swap in the esbuild CSS parser #329 Going to close this in favor of that.

@natemoo-re natemoo-re closed this Mar 14, 2022
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.

3 participants