Giter Site home page Giter Site logo

Comments (6)

atomiks avatar atomiks commented on May 27, 2024 1

I couldn't reproduce this with React 17 or 18 with a basic snapshot test using Vitest (both conditional and unconditional FloatingPortal rendering based on an open state), using latest @testing-library/react and jsdom. Maybe it's a React 16 problem in a testing env, or something else, but it doesn't seem to be an actual bug. Feel free to provide a reproduction if you have the ability, but for now, I'm closing due to lack of ability to reproduce the issue.

from floating-ui.

atomiks avatar atomiks commented on May 27, 2024

Is this only in snapshot tests? In the browser it's defined with both conditional and unconditional rendering.

from floating-ui.

smellai avatar smellai commented on May 27, 2024

Yes, you're right, it happens only in jest snapshots, any idea why it could be?

from floating-ui.

smellai avatar smellai commented on May 27, 2024

Hi, I finally managed to set up a reproduction: https://stackblitz.com/edit/vitejs-vite-erxqfe?file=src%2F__snapshots__%2FPopover.spec.js.snap

you can see id="undefined" at line 19

from floating-ui.

atomiks avatar atomiks commented on May 27, 2024

Have you tried:

  • Upgrading to React 18, which uses the native useId() hook and has better perf (I'm going to drop React 17 support when React 19 comes out in a few months anyway)
  • Adding act(async () => {}) after the render() call in the test async (it breaks in Stackblitz, not sure why)
  • Avoiding snapshot tests which can easily break when implementation details of this library change (such as here) even though it's not actually broken for real users

from floating-ui.

smellai avatar smellai commented on May 27, 2024
  • I'm maintaining an npm module so I'm not free to upgrade to React 18 right away, until my consumers are ready.
  • using act doesn't seem to change this behaviour.
  • I know snapshots tests are very limited, but they actually helped in finding bugs after library upgrades. They can be replaced for sure with better tests, but until we don't have the resources to do that, that's the best we have.

I understand my specific issue shouldn't be a priority for you and I'm glad you always take the time to answer in zero time. Thank you!

from floating-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.