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

Style/Script Defaults #150

Merged
merged 3 commits into from
Mar 22, 2022
Merged

Style/Script Defaults #150

merged 3 commits into from
Mar 22, 2022

Conversation

natemoo-re
Copy link
Member

@natemoo-re natemoo-re commented Mar 15, 2022

  • Start Date: 2022-03-15
  • Status: ✅ Accepted

Summary

Astro is inconsist between <style> and <script> default behavior. Currently, <style> has opt-out processing, but <script> does not. This RFC aims to settle on a good, consistent default for both <style> and <script>.

TLDR; <script hoist> becomes the default for <script>. is:inline introduced for <script> and <style>.

Links

@matthewp
Copy link
Contributor

matthewp commented Mar 15, 2022

I have some clarifying questions posted above, but are not blocking in my mind. I agree with this RFC.


I'll add that I think <img> and <link rel="stylesheet"> should also be "automagic", but that is not blocking this RFC, happy to start a new one to discuss.

@bholmesdev
Copy link
Contributor

RFC call notes: 03-15-2022

  • Did not reach consensus
  • Open questions:
    • Should lang:scss and is:inline work together? Currently not supported
    • Can is:raw be re-used instead of is:inline? - con: teaches user to use otherwise dangerous tag for HTML
    • We can use src= with <script hoist> currently. Should we still switch to is:inline as proposed? - current answer: no, we should probably ditch this from the RFC!

@sciencefidelity
Copy link

I found a use case for this. In the last few days I've been experimenting with creating html email templates that populate and compile from a CMS (Sanity). For this use case all styles need to be inlined, I'd prefer to use lang:scss.

I have some questions:

  • Do is:inline styles get optimised?
  • Where on the complied page do styles get inlined, (ie are they be moved to head)?
  • What happens when multiple .astro components containing <style is:inline> compile to a single .html file?

@RafidMuhymin
Copy link
Member

If there's no way to flag a <script> tag for hosting manually, and if adding any attributes or the define:vars directive will exclude the tag from hosting, then won't this approach break a few valid use cases? I think at least the define:vars directive should be supported for hoistin

@matthewp
Copy link
Contributor

@RafidMuhymin define:vars already isn't supported for hoisting. We would like to support it but just haven't figured out how to do so. We need to build the JavaScript before rendering, but then some how feed the rendered variables back into it. It's a hard problem.

Copy link

@tony-sull tony-sull left a comment

Choose a reason for hiding this comment

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

Added one comment related to potentially removing is:scoped, but not a blocker for me

Very happy to see how all this came together! It makes much more sense having styles and scripts handled in the same way, and defaulting to compiler/bundler magic makes sense since that seems to be the lion's share of real world use cases

@gloopsies
Copy link

@RafidMuhymin define:vars already isn't supported for hoisting. We would like to support it but just haven't figured out how to do so. We need to build the JavaScript before rendering, but then some how feed the rendered variables back into it. It's a hard problem.

I know that currently define:vars works by adding let variable = value, but that sounds wrong to me. Could Astro move to more of like a preprocessor way of replacing every occurrence of variable with it's value? or at least using const insted of let?

@natemoo-re natemoo-re force-pushed the style-script-defaults branch from 8bd399a to 97a0416 Compare March 22, 2022 19:44
@natemoo-re natemoo-re merged commit dd23d6b into main Mar 22, 2022
@FredKSchott
Copy link
Member

Accepted during todays RFC call

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.

8 participants