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.

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:open
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chaancecommented, Aug 2, 2021

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.

1reaction
chaancecommented, Aug 2, 2021

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.

Read more comments on GitHub >

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

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