Rendering bug in either descendants or react
See original GitHub issueš Bug report
Current Behavior
I might of setup my test case wrong, but I think its right.
Iāve written tests for React Testing Library as well as a helper to check if the bug is present.
5% of the time the descendants code will register the wrong indexes.
Expected behavior
no indexes to be wrong.
Reproducible example
CodeSandbox Example GitHub Source
Suggested solution(s)
again, not sure what the issue is here, and quite possibly could be a bug in react.
Additional context
You can run the example app locally, and use this code to mimic the test I have written.
function testcase() {
document.querySelector('button').click();
Array.from(document.querySelectorAll('span')).forEach(el => {
console.assert(el.textContent.endsWith(el.parentElement.getAttribute('data-index')))
})
}
// once testcase is defined in the console, call this {n} times till you see the assert error.
testcase();
Your environment
Software | Name(s) | Version |
---|---|---|
Reach Package | descendants | 0.15.3 |
React | react | 17.0.2 |
Browser | chrome | 92.0.4515.107 |
Assistive tech | N/A | |
Node | node | 14.17.3 |
npm/yarn | npm | 7.20.1 |
Operating System | Zorin OS Linux | 16 |
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Why React Re-Renders - Josh W Comeau
When a component re-renders, it tries to re-render all descendants, regardless of whether they're being passed a particular state variableĀ ...
Read more >React Components rendered twice ā any way to fix this?
React will soon provide a new Concurrent Mode which will break render work into multiple parts. Pausing and resuming the work between this...
Read more >Strict Mode - React
StrictMode is a tool for highlighting potential problems in an application. Like Fragment , StrictMode does not render any visible UI. It activates...
Read more >Prevent Multiple Renders in React - YouTube
Strict Mode does not render any visibble UI in React, ... twice - React component rendering twice If you are having any of...
Read more ><div> cannot appear as a descendant of <p> - Stack Overflow
Either a string to use a DOM element or a component. ... Based on the warning message, the component ReactTooltip renders an HTML...
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
Closing because I think I found and fixed the bug, but I added a note to the release to explain the potential unexpected issues you might encounter along the way. Descendants are only registered/unregistered when new items enter/leave the list but not when existing items move around.
The good news: I do believe you found a bug, and I think it should be fixed in the next release. Thanks for that! Itāll change some of our APIs a bit and require a little more boilerplate in the consumer packages, but this is technically an internal package so Iām not super concerned about that.
That said, even with the fix, Iām not sure itāll work for your use case here. I donāt know that we need that sort of descendant nesting youāre going for. If you can get it to work consistently and keep things performant Iāll be happy to take a PR, but just as a disclaimer itās possible that we keep changing things indiscriminately without regards to semver, so I might still fork it or try your own solution if youāre currently using it directly.