Skip to content

Elements rendered outside the shadow root #727

Closed

Description

@dimi-nk

Stencil version:

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://stencil-worldwide.slack.com

Current behavior:
Elements seem to be rendered outside the shadow root.

Expected behavior:
All elements in the template are rendered inside the shadow root

Steps to reproduce:

I've reproduced the issue here: https://github.com/dimi-nk/stencil-show-render-error

  • Clone project & npm install
  • Run with npm start
  • Read the note at the bottom

These are the generated elements after navigating back to page 1.
image

image

Other information:

Activity

  1. dimi-nk commented on Apr 12, 2018

    @dimi-nk
    Author

    It might be the way I render the child components:

     // this fails
      render() {
        return this.values.map(value => {
          return <div>{value.value}</div>;
        });
      }
    
     // this works
      render2() {
        const a = this.values.map(value => {
          return <div>{value.value}</div>;
        });
        return (<main>{a}</main>);
      }
  2. jgw96 commented on Apr 12, 2018

    @jgw96
    Contributor

    Hello! Thanks for using Stencil. I am not able to reproduce this issue with the latest version of Stencil. I would recommend updating to 0.7.20.

  3. dimi-nk commented on Apr 12, 2018

    @dimi-nk
    Author

    I can still see this issue after updating

  4. reopened this on Apr 12, 2018
  5. added and removed on Apr 12, 2018
  6. doliG commented on Apr 12, 2018

    @doliG

    Hello @dimi-nk ,

    I think it's because you try to return an array of JSX element in your first example.

    In my experience, when you try to return an array of JSX elements with React, you get the following error: Adjacent JSX elements must be wrapped in an enclosing tag

    In your case and because you're not using react, you should try to wrap what you return in another JSX element just like you did in render2().

    I think something like this should work:

    render() {
      return (
        <div>
          {this.values.map(value => <div>{value.value}</div>}
        <div>
      );
    }

    Note that there is no need to use return in an arrow function (except if you find it's better for readability 😉).

    I suggest you these readings:
    https://reactjs.org/docs/fragments.html
    https://codeburst.io/fragment-in-react-1cd69f158910

    Let me know if it helps 😊

  7. dimi-nk commented on Apr 12, 2018

    @dimi-nk
    Author

    Hey @doliG thanks for the info (I know the arrow fn part 😂 ).

    I have a few cases in stencil components where I do this (and it works just fine):

    return [<div></div>, <div></div>];

    example
    image

    Any ideas?

  8. juanmiguelbesada commented on Apr 13, 2018

    @juanmiguelbesada
    Contributor

    I still can reproduce this issue in 0.7.24

  9. jgw96 commented on Apr 19, 2018

    @jgw96
    Contributor

    Hello all! We are currently refactoring slots which should fix this issue. I will give this another test once that is done.

  10. self-assigned this
    on Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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