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

key="0" attribute on root element disrupts rendering #113

Open
kromit opened this issue Apr 27, 2020 · 3 comments
Open

key="0" attribute on root element disrupts rendering #113

kromit opened this issue Apr 27, 2020 · 3 comments

Comments

@kromit
Copy link

kromit commented Apr 27, 2020

When processing multiple HTML chunks <p>mytext-1</p>, <p>mytext-2</p>, <p>mytext-3</p>
the parser generates key="0" attribute every time.

<div>
  {parser.parse('<p>mytext-1</p>`')}
  {parser.parse('<p>mytext-2</p>`')}
  {parser.parse('<p>mytext-3</p>`')}
</div>

This causes react-warnings and disrupts rendering since the children can not be distinguished from each other with same key="0" attribute.

key="0" on root element should not be rendered at all.

react warning:

Warning: Encountered two children with the same key, 0. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

@kromit kromit changed the title key="0" attribute on root element disrupts rendering performance key="0" attribute on root element disrupts rendering Apr 27, 2020
@aknuds1 aknuds1 added the bug label May 23, 2020
@aknuds1
Copy link
Owner

aknuds1 commented May 23, 2020

Can't you easily solve this by enclosing the parsed chunks in div elements? For example:

<div>
  {parser.parse('<p>mytext-1</p>`')}
</div>
<div>
  {parser.parse('<p>mytext-2</p>`')}
</div>
<div>
  {parser.parse('<p>mytext-3</p>`')}
</div>

@aknuds1 aknuds1 removed the bug label May 23, 2020
@aknuds1
Copy link
Owner

aknuds1 commented May 23, 2020

Also, can't you concatenate the HTML chunks into a single document, that you then parse? That sounds like a better approach to me.

@kromit
Copy link
Author

kromit commented Jun 3, 2020

Yes, thank you. I know the workarounds, but I can not use them since the processing is dynamic, so I do not have all snippets and I can not change the HTML structure.

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

2 participants