Skip to content

Potentially misleading documented behaviour of define:vars  #3165

@ohansemmanuel

Description

@ohansemmanuel

Hi there,

The following section of the doc seems rather misleading:

https://docs.astro.build/en/reference/directives-reference/#definevars

(1) above describes define:vars with respect to both <style> and <script>
(2) describes only the behaviour with <script>

The problem here is with (1)

Correct me if I'm wrong but using define:vars in a <style> within a component markup still bundles the component styles i.e., contrary to what's documented here.

Consider an example with a single component rendered three times and define:vars used on both <style> and <script> elements.

CleanShot 2023-05-04 at 11 54 29

  • 1, 2,3 in the screenshot above: the script is inlined as expected. Everything else holds true for the script.

However, this isn't the case for the styles.

  • the variable is locally declared on the parent element in the markup
  • the style isn't added multiple times with multiple component use (as with a script inline directive)
  • the component style is still bundled and locally scoped (not global)

Does the doc here need to be adjusted to exclude styles? i.e., (1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    improve or update documentationEnhance / update existing documentation (e.g. add example, improve description, update for changes)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions