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

Template elements shouldn't need to parse themselves until requested #2

Open
Westbrook opened this issue Oct 3, 2024 · 1 comment

Comments

@Westbrook
Copy link

Westbrook commented Oct 3, 2024

With the suggestion of:

<template>
    <style export="/foo.css">
        #content {
            color: red;
        }
    </style>
</template>

There implies the need that <template> be changed to parse and know its contents, while today they are inert by default.

Why force a change to the parser when leveraging a type of <style> would be enough to prevent the styles from being applied to the page and the export or specifier attributes be the part that explain the usage?

Applying to the page and available for consumption off the module graph:

<style export="/foo.css">
   /* ... */
</style>

NOT applying to the page but available for consumption off the module graph:

<style type="module" export="/foo.css">
   /* ... */
</style>

This then can neatly be paralleled in other content types:

<template type="module" export="/foo.html">
<!-- -->
</template>
<script type="json" export="/foo.json">
<!-- -->
</script>
<script type="module" export="/foo.js">
<!-- -->
</script>

Etc.

@robglidden
Copy link

Excellent point.

In Chrome:

<style type="module" export="/foo.css">
    section {
        border: medium dashed red;
    }
</style>

is indeed ignored in the light DOM.

However, MDN lists the type attribute on the style element under Deprecated Attributes, explaining "This attribute should not be provided: if it is, the only permitted values are the empty string or a case-insensitive match for text/css."

But the living specification says: "if element's type attribute is present and its value is neither the empty string nor an ASCII case-insensitive match for "text/css", then return."

So I think this would work, but I do not know if there is some backward compatibility or history that I am missing.

Also, this technique would not work for SVGs, on which type="module" has no effect. But I assume it would work for <script type="application/json" export="/foo.json">.

But in any case, a change in the parser would be needed to recognize the export, which as I understand it is a core idea of the explainer/proposal.

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

No branches or pull requests

2 participants