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.

DOM elements duplicated on rerendering

See original GitHub issue

So I have couple of boilerplate projects which show how to use https://github.com/capaj/systemjs-hot-reloader with different frameworks. I wanted to get one for preact as well, but that proved harder than it should be. First reason was your custom jsx which I think I can solve with @guybedford but the other one which you might help me with was something that bit me when I rerender a preact app.

I have this very simple hello world app: https://github.com/capaj/jspm-preact/blob/master/public/app.js#L13

All it does is render Hello world. Now when render is called second time(because we reloaded some module and want to refresh the app) it actually appends another Hello world into my ‘app’ div element. I haven’t had any such behaviour with react. React render() always deterministically returns same DOM, overwriting the current elements.

Do you have any reason that this is how preact render method behaves? If not, could you please align the behaviour with react? Then I could drop this little hack: https://github.com/capaj/jspm-preact/blob/master/public/app.js#L16

Thanks for consideration.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
qwertiecommented, Apr 29, 2018

Gee, wouldn’t it make more sense to make React’s behavior the default, and then change behavior if there is a third argument?

Read more comments on GitHub >

github_iconTop Results From Across the Web

DOM elements duplicated on rerendering · Issue #49 - GitHub
I haven't had any such behaviour with react. React render() always deterministically returns same DOM, overwriting the current elements.
Read more >
Reusing react component duplicates DOM elements
I have created a React component which opens a form for input parameters and once the form is submitted, a call is made...
Read more >
Why you need keys for collections in React. - paulgray.net
Keys are important when rendering collections of items in React. ... React does not render duplicate keys. ... The output DOM is then:....
Read more >
Reconciliation - React
When comparing two React DOM elements of the same type, React looks at the attributes ... rerender in this context means calling render...
Read more >
Re-rendering - Rhubarb PHP
This results in brand new DOM elements being created to replace the original ones. The View Bridge base class handles reconnecting the View...
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