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.

unexpect `class` rendered with merge

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
csbuncommented, Aug 26, 2016

What a great Job! Thanks! 谢谢!

0reactions
developitcommented, Aug 25, 2016
Read more comments on GitHub >

github_iconTop 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 >

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