Skip to content

feat: make position of <style> tags configurable in hydrateDocument() #5915

Closed
AnirudhJalagam/ionic-frameworkss
#2

Description

@mhoritani

Prerequisites

Describe the Feature Request

It would be helpful if hydrateDocument() could be configured as to where generated inline <style> tags will be placed.

Describe the Use Case

When the document is hydrated, the inline <style> tags created for the Stencil components are placed at the top of the <head> section. This placement can delay the loading of <link> tags, such as those with a rel="preconnect" value, which are crucial for performance optimization. Ideally, the placement of these styles should be configurable to avoid such issues.

Sample input:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <link rel="preconnect" href="https://some-url.com" />
    </head>
    <body>
        <my-component></my-component>
    </body>
</html>

Output:

<!doctype html>
<html lang="en" data-stencil-build="vuogzrh7" class="hydrated">
    <head>
        <meta charset="UTF-8" />

        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style sty-id="sc-my-component">
            /*!@:host*/
            .sc-my-component-h {
                display: inline-block;
                border: 1px solid red;
                padding: 5px;
            }
        </style>
        <link rel="preconnect" href="https://some-url.com" />
    </head>
    <body>
        <my-component class="sc-my-component-h hydrated" s-id="1"
            ><!--r.1-->
            <div class="sc-my-component" c-id="1.0.0.0">
                <!--t.1.1.1.0-->My Component
            </div></my-component
        >
    </body>
</html>

Describe Preferred Solution

Make hydrateDocument() configurable as to where generated style tags are placed.

Describe Alternatives

No response

Related Code

A well-documented reproduction of the use-case/issue can be found here:
https://github.com/mhoritani/stencil-repro-072024

Additional Information

No response

Activity

  1. changed the title [-]feat: position of `<style>` tags should be configurable in `hydrateDocument`[/-] [+]feat: make position of `<style>` tags configurable in `hydrateDocument()`[/+] on Jul 30, 2024
  2. christian-bromann commented on Jul 30, 2024

    @christian-bromann
    Member

    Thanks for reporting @mhoritani , I think changing the order makes totally sense. Any contributions are much appreciated!

  3. added
    Feature: Want this? Upvote it!
    and removed on Jul 30, 2024
  4. mhoritani commented on Jul 31, 2024

    @mhoritani
    Author

    Happy to have a look @christian-bromann. Any chance of pointing us in the right direction?

  5. added
    Resolution: Refine
    and removed
    Feature: Want this? Upvote it!
    on Aug 1, 2024
  6. christian-bromann commented on Aug 5, 2024

    @christian-bromann
    Member

    @mhoritani I pulled the issue into the sprint to take a look at.

    For future reference, this behavior was introduced in 05d242d unfortunately with no further explanation on the reason.

  7. christian-bromann commented on Aug 26, 2024

    @christian-bromann
    Member

    A fix for this bug has been published in Stencil v4.21.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Help WantedResolution: Refine

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions