Skip to content

bug: adoptedStyleSheets's mutable before chrome 99 #6326

Closed
ionic-team/ionic-framework
#30524

Description

@liuwin7

Prerequisites

Stencil Version

4.33.0

Current Behavior

App will crash when running on chrome < 99.

https://github.com/stenciljs/core/src/utils/shadow-root.ts

  if (globalStyleSheet) shadowRoot.adoptedStyleSheets.push(globalStyleSheet);

https://github.com/stenciljs/core/src/runtime/styles.ts

      styleContainerNode.adoptedStyleSheets.push(style);

Reffer:
1, https://blog.chromium.org/2022/02/chrome-99-css-cascade-layers-new-picker.html#:~:text=document.adoptedStyleSheets%20is%20Now%20Mutable
2. https://chromestatus.com/feature/5638996492288000

Expected Behavior

Not crash when using chrome < 99

System Info

TypeError: Cannot add property 0, object is not extensible
    at Array.push (<anonymous>)
    at HTMLElement.createShadowRoot (:8100/node_modules/.vite/deps/chunk-HEIOVAU6.js?v=d73e29c9:528)
    at HTMLElement.__attachShadow (:8100/node_modules/.vite/deps/chunk-HEIOVAU6.js?v=d73e29c9:3706)

Steps to Reproduce

Using Chrome < 99, it will reproduce

Code Reproduction URL

No

Additional Information

No response

Activity

  1. aeharding commented on Jul 1, 2025

    @aeharding
    Contributor

    Hi! Can you upgrade chrome? That is 3 years old, lots of security issues.

    Mutating the adoptedStyleSheets is better for performance is and MDN best practice.

  2. liuwin7 commented on Jul 2, 2025

    @liuwin7
    Author

    Yes, it is indeed a very old version.
    But as the description in https://stenciljs.com/docs/support-policy#browser-support, v4 has a lowest version chrome 79+.
    If using the mutating adoptedStyleSheets, maybe you should modify the indication for the compatibility.

    At the meantime, the ionic/[email protected] has use this version, 4.33.0, which will also impact the IONIC's compatibility.
    https://github.com/ionic-team/ionic-framework/blob/v8.6.0/core/package.json

  3. aeharding commented on Jul 2, 2025

    @aeharding
    Contributor

    Interesting. From that same page on support, Stencil v4 is claimed to support iOS 14+, but adoptedStyleSheets didn't exist until iOS 16.4.

    At the meantime, the ionic/[email protected] has use this version, 4.33.0, which will also impact the IONIC's compatibility.

    Is there a specific component or thing that isn't working for you? I just checked Ionic's kitchen sink demo (8.6.2) on Chrome 99 from Browserstack, and everything works ok. A reproduction example would be helpful.

  4. johnjenkins commented on Jul 2, 2025

    @johnjenkins
    Contributor

    @aeharding it checks for support and falls back to style tag

  5. liuwin7 commented on Jul 2, 2025

    @liuwin7
    Author

    Chrome 99 is fine, because the mutable feature is shipped from Chrome 99 according to https://chromestatus.com/feature/5638996492288000 .

    You can use Chrome 98 to reproduce it. @aeharding

  6. petercmuc commented on Jul 7, 2025

    @petercmuc

    We face the same error. Unfortunately our customers won't all switch to newer Chrome/Edge versions.

    The bug can be easily reproduced with the stencil cli scaffolding.
    However, it only happens when I used the "production" mode. In dev mode it works fine

  7. added 2 commits that reference this issue on Jul 7, 2025
    1e4624c
    ed43236
  8. added a commit that references this issue on Jul 7, 2025
    2f363dd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions