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

Custom elements only works the first time? #1342

Closed
YerkoPalma opened this issue Nov 30, 2018 · 7 comments
Closed

Custom elements only works the first time? #1342

YerkoPalma opened this issue Nov 30, 2018 · 7 comments

Comments

@YerkoPalma
Copy link

🐛 bug report

Description of the problem

I'm using litElement to play with custom elements (but I guess the same happen to native custom elements) and the first time I run my app it works well, but after any change it complains

image

It seems like it tries to register a new component every time.

How has this issue affected you? What are you trying to accomplish?

Just a side project, but quite annoying bug actually.

Link to sandbox: link

Your Environment

Software Name/Version
Сodesandbox latest?
Browser Chrome Versión 70.0.3538.110 (Build oficial) (64 bits)
Operating System Windows 10
@YerkoPalma
Copy link
Author

To reproduce:

  • Go to the linked sandbox and wait it to load
  • Make any minor change (like changing this.mood = 'happy' to this.mood = 'Happy')
  • Watch the error

@CompuIves
Copy link
Member

Hmm, it seems like the sandbox relies on global state. This can be fixed in two ways:

  1. Create a sandbox.config.json and enable in that config: 'Hard reload' (this refreshes the page on every change).
  2. Create a sandbox.config.json and mark the template as static. This disables the bundler.

@CompuIves
Copy link
Member

Here's an example sandbox: https://codesandbox.io/s/pj42p1v6wm

@orlov-vo
Copy link

You should define custom element only once. You can't to redefine it. It is prohibited in the spec. I guess you can get a new version of your component via module.hot.accept and call render again?

It is similar with: skatejs/skatejs#564

@YerkoPalma
Copy link
Author

@orlov-vo I'm not redefining custom elements, it is just that I run the same code more than once (because I'm developing). @Compulves I'll try the static option later, thanks for the response

@YerkoPalma
Copy link
Author

@CompuIves this is solved, thanks for your response

@qwabra
Copy link

qwabra commented Dec 11, 2018

in pure customElements

"hardReloadOnChange": true, didn't help me
but set template as static is works

Hmm, it seems like the sandbox relies on global state. This can be fixed in two ways:

  1. Create a sandbox.config.json and enable in that config: 'Hard reload' (this refreshes the page on every change).
  2. Create a sandbox.config.json and mark the template as static. This disables the bundler.

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

4 participants