unexpect `class` rendered with merge
See original GitHub issueI used preact-render-to-string as a server-side rendering tool and rerender on the client-side with merge.
import { h, render, Component } from 'preact';
/** @jsx h */
class Cmp extends Component {
render() {
return <p id="cmp" className="my-cmp">Cmp</p>;
}
}
class App extends Component {
render() {
return (<div id="my-app">
<p id="before">Before</p>
<Cmp />
<p id="after-1">After1</p>
<p id="after-2">After2</p>
<p id="after-3">After3</p>
</div>);
}
}
- server-side rendering
import { h } from 'preact';
import render from 'preact-render-to-string';
const ssrHtml = render(<App />);
res.send(`
<div>Preact</div>
<div id="container">${ssrHtml}</div>
<div id="log"></div>
`);
- client-side rendering
import { h, render } from 'preact';
render(
<App />,
document.getElementById('container'),
document.getElementById('my-app')
);
Here is the full example on codepen.
As the result comes out, there is an unexpect class
on p#after-1
:
Server-side Rendering:
<div id="my-app"><p id="before">Before</p><p id="cmp">Cmp</p><p id="after-1">After1</p><p id="after-2">After2</p><p id="after-3">After3</p></div>
Meanwhile Client-side Rendering:
<div id="my-app"><p id="before">Before</p><p id="cmp">Cmp</p><p id="after-1" class="">After1</p><p id="after-2">After2</p><p id="after-3">After3</p></div>
And when I debug on Chrome DevTool, it seems p#my-cmp
, p#after-1
, p#after-2
, p#after-3
are all replaced. removeOrphanedChildren
was call twice.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Unexpected outcome with merging react state - Stack Overflow
I think I'm just confused because right below that in the docs, it says it will leave the rest of the other state...
Read more >unexpected behavior when merging nested functions ... - GitHub
I recently upgraded to v4 of lodash.merge, and some of the behavior seems to have changed: var merge = require('lodash.merge'); ...
Read more >React.Component
React lets you define components as classes or functions. ... The render() method is the only required method in a class component.
Read more >Render #pre_render callbacks must be methods of a class ...
When using field_groups in Drupal 9, I'm getting this exception when calling e.g. /admin/config/people/accounts:
Read more >'java.lang.RuntimeException Error rendering template for ...
Template.merge(Template.java:328) ... Caused by: java.lang.RuntimeException: Error rendering template for decorator page at ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What a great Job! Thanks! 谢谢!
@csbun Confirmed fixed in 6.0.0 (beta): http://codepen.io/developit/pen/BzgVvy?editors=0010#0