Skip to content

Support ShadowDom Polyfills (not just Scoped Fallback) #2012

Closed as not planned

Description

@umdjm

Stencil version:

I'm submitting a:
[X] bug report
[X] feature request
[ ] support request

Current behavior:
Using a stencil component with slots doesn't work correctly in React on IE11.

The fallback to scoped approach doesn't work for React because the light-dom elements are moved and React gets confused.

To demonstrate, I created https://umdjm.github.io/StencilFallbackDemo/, which is adapted from the React in One Minute Demo.

On IE11, when you click "Like" the Stencil component fails to render with the template:

On Chrome, when you click "Like" the Stencil component shows the slot as expected:

FWIW, this repro worked fine when we created the same Web Component with LitElement.

I think the right fix for this is to support using Shadow Dom polyfills instead of the fallback to scoped approach.

We tried to load the ShadowDom polyfills ourselves, but ran into issues with CSS selectors. The scoped CSS rewrites don't happen when the polyfills exist. Stencil should provide us with a way to enable ShadowDom polyfills correctly so that slots and CSS work well.

Steps to reproduce:

  1. Create a stencil component that has a slot
  2. Fix the fact that IE11 doesn't call render when children change by adding a mutation observer - see Slot Changes Re-Rendered in Wrong Location on IE11/Edge #2004 (comment)
  3. Use that component in a React App

Related code:

Stencil Component:

  render() {
    return <div>
      HEADER

      <br/>

      SLOT (
        <slot />
      )

      <br/>
      FOOTER
    </div>;
  }

React App:

          <my-component>
            {this.state.liked
              ? <p>Button was clicked!</p>
              : "Click the button"
            }
          </my-component>

Activity

  1. schadenn commented on Nov 22, 2019

    @schadenn

    Opened #2031 with a quick fix to enable forcing shadow Dom in IE - tested it in our codebase together with @webcomponents/webcomponentsjs

  2. patrickalima98 commented on Nov 23, 2019

    @patrickalima98

    The same problem here, I'm using the version 1.8.1, in my case, I'm make a library like Bootstrap, and all my componentes have this problem in the SSR in Firefox and Chrome.

  3. markcellus commented on Jan 9, 2020

    @markcellus

    FWIW, I definitely agree with @schadenn's comment in #2031 (comment).

    Stencil should just remove the "scope fallback code" and just let consumers use webcomponentsjs polyfills if needed. That would likely help with these issues.

  4. sschottler commented on Feb 2, 2020

    @sschottler

    There are three work-arounds that will render correctly:

    1. wrap each conditional result in same tag type:
                  <my-component>
                    {this.state.liked ? (
                      <p>Button was clicked!</p>
                    ) : (
                      <p>Click the button</p>
                    )}
                  </my-component>
    1. wrap the conditional expression in an extraneous tag like span or div (not ideal for semantic markup, but gets the job done):
                  <my-component>
                    <div>
                      {this.state.liked ? (
                        <p>Button was clicked!</p>
                      ) : (
                        "Click the button"
                      )}
                    </div>
                  </my-component>
    1. use <React.Fragment> (or the shorthand <>…</>) for simple cases with just string messages where you don’t want extraneous markup:
                  <my-component>
                    {this.state.liked ? (
                      <React.Fragment>Button was clicked!</React.Fragment>
                    ) : (
                      <React.Fragment>Click the button</React.Fragment>
                    )}
                  </my-component>

    Basically anything that ensures the first child node that gets relocated to the slot remains the same type could work. I suspect the issue is because react's internal fiber tree probably has the relocated child node at different position from where it ultimately ends up after slot relocation. Then after state change, reconciliation detects tag type change so react tries to remove child and append new child based on incorrect fiber model of committed dom structure.

    This commit addressed a bug with appendChild and stencil's light-dom slot logic. Not sure if that fix also addresses this issue and have not tested it myself yet.

    Also, it seems stencil's slot relocation logic correctly renders surrounding template elements on initial render, but not on update, so maybe something in connectedCallback or in the relocateSlotContent logic needs to be refreshed when children change.

  5. hypery2k commented on Feb 12, 2020

    @hypery2k

    the same is happening in Angular when using innerHTML directive. But if you wrap it within one native dom element it's working
    So this doesn't work in Edge/IE:

    <my-comp [innerHTML]="data.html">
    </my-comp>
    

    But this does:

    <my-comp>
       <div [innerHTML]="data.html"></div>
    </my-comp>
    
  6. Sanderand commented on Nov 17, 2020

    @Sanderand

    Is there an update on this issue? It's still relevant for the latest Stencil version (2.3.0)

  7. rwaskiewicz commented on Sep 6, 2023

    @rwaskiewicz
    Member

    Hey there 👋

    I apologize that it took so long for a member of the team to acknowledge this ticket. With Stencil v3, we've officially deprecated support for IE 11/older versions of Edge. At this time, we're not looking to add support for ShadowDom polyfills. As such, I'm going to close this out. Again, I apologize for the lack of response from the team here.

  8. added
    deprecated_browser_support
    and removed on Sep 6, 2023
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

    deprecated_browser_support

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions