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

prerender: shadow root undefined if used in component did load #2301

Closed
peterpeterparker opened this issue Mar 23, 2020 · 1 comment
Closed

Comments

@peterpeterparker
Copy link
Contributor

Stencil version:
stencil/core@1.11.x but seems the problem exists since a while

I'm submitting a:
[X] bug report

Current behavior:
I trier to chase that issue since almost a week without any success. I'm not able to build a Stencil app with prerendering if a shadowed component use any property or functions of el.shadowroot
at the componentDidLoad lifecycle.

Furthermore I'm able to reproduce the problem with an empty sample component and app (see steps to reproduce)

[53:21.6]  prerendering failed in 1.21 s

[ ERROR ]  Hydrate Error
           TypeError: Cannot read property 'querySelector' of null at MyComponent.componentDidLoad
           (/Users/daviddalbusco/projects/lab/stencil-prerendering/my-app/dist/hydrate/index.js:16003:41) at safeCall
           (/Users/daviddalbusco/projects/lab/stencil-prerendering/my-app/dist/hydrate/index.js:5984:36) at
           postUpdateComponent
           (/Users/daviddalbusco/projects/lab/stencil-prerendering/my-app/dist/hydrate/index.js:5938:13) at postUpdate
           (/Users/daviddalbusco/projects/lab/stencil-prerendering/my-app/dist/hydrate/index.js:5905:34) at
           updateComponent
           (/Users/daviddalbusco/projects/lab/stencil-prerendering/my-app/dist/hydrate/index.js:5907:13) at update
           (/Users/daviddalbusco/projects/lab/stencil-prerendering/my-app/dist/hydrate/index.js:5828:26) at
           /Users/daviddalbusco/projects/lab/stencil-prerendering/my-app/dist/hydrate/index.js:6951:13 at
           processTicksAndRejections (internal/process/task_queues.js:79:11)

npm ERR! code ELIFECYCLE

Expected behavior:
Being able to prerender even if shadow root is use at the component did load lifecycle

Steps to reproduce:

git clone https://github.com/peterpeterparker/stencil-prerendering

cd stencil-prerendering/my-component
npm install
npm build

cd ../my-app
npm install
npm build

Related code:

componentDidLoad() {
    const elem: HTMLDivElement = this.el.shadowRoot.querySelector('div');

    console.log(elem);
  }
@ionitron-bot ionitron-bot bot added the triage label Mar 23, 2020
@peterpeterparker peterpeterparker changed the title pretender: shadow root undefined if used in component did load prerender: shadow root undefined if used in component did load Mar 23, 2020
@simonhaenisch simonhaenisch added bug and removed triage labels Mar 23, 2020
@markcellus
Copy link

Running into this same issue. Does this mean there is no reliable way to query an element in the shadow root of a component? 😳

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

3 participants