question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Elements can be undefined in component clean-up when importing the project using `<script>`

See original GitHub issue

Describe the bug ref={...} is used in a few places to attach and detach events when components are created and removed.

There’s possibly a Stencil bug, not too trivial to debug, which causes componentDidUnload to be called before componentDidLoad when importing Shoelace into another Stencil app using <script> tags, and embedding a Shoelace component within a host app component.

Using an alternate import method via npm i @shoelace-style/shoelace@2.0.0-beta.10 and adding import '@shoelace-style/shoelace'; to the index.ts file means the error doesn’t reproduce. Also, removing the wrapping host component with a slot also fixed the issue.

To Reproduce In the host Stencil app we have something like:

<app-card>
  <sl-details open={true}></sl-details>
</app-card>

and Shoelace is installed within the app defining the following in the index.html:

<script
      type="module"
      src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.10/dist/shoelace/shoelace.esm.js"
    ></script>

When running npm start, starting the default Stencil dev server, we see errors that componentDidUnload is calling an unobserve but el is undefined.

Adding breakpoint within didLoad and didUnload you can see that didUnload is called before didLoad.

Expected behavior

Both installation methods for Shoelace perform the same.

Additional context

Likely a Stencil bug but adding here as there are ways to mitigate. The error may go away if switching to disconnectedCallback and this issue may provide motivation to make that change.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nathanb21commented, Aug 7, 2020

npm run build then serving from the www folder and I don’t see any errors.

If I set:

devServer: {
    reloadStrategy: null
  }

the error still pops up. Obviously something in the dev server setup, though!

0reactions
claviskacommented, Oct 23, 2020

I’m going to close this since I can’t reproduce the problem. A minimal test case will help narrow down what’s happening, so if someone can provide one I’ll reopen this and investigate it further.

If it does turn out to be an upstream issue, the test case will still be helpful so we can forward it to the right project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Some components "cannot be used as a JSX component"
I fixed this problem in my React Native, Typescript project by changing how I imported React. I changed my import statement to this:....
Read more >
TypeError: Cannot read property 'createElement' of undefined ...
createElement seems to be undefined inside react-testing-library . Or I have Jest misconfigured? Suggested solution: My first thought was that ...
Read more >
Troubleshooting common React Native bugs - LogRocket Blog
This troubleshooting guide shares how to easily find and address common React Native bugs. See common error examples.
Read more >
Why and How to Use Absolute Imports in React
An easy way to maintain clean code in React.
Read more >
ReactDOM – React
import * as ReactDOM from 'react-dom';. If you use ES5 with npm, you can write: var ReactDOM = require('react-dom');. The react-dom package also...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found