Coder Social home page Coder Social logo

Comments (5)

markerikson avatar markerikson commented on July 27, 2024

I'd love to see this myself. There's actually a couple very relevant PRs here:

But the comment on that by Joe was somewhat discouraging:

We discussed this as a team a while back, and we are very concerned about the cost of supporting this long-term. Although the intent would be just for non-critical (to application correctness) things like performance monitoring, itโ€™s inevitable that applications or libraries would end up relying on these hooks for their core behavior. That would slow us down since it would make many more internal refactors into breaking changes, delaying those refactors and the improvements they would unlock.
We think the right first step is the transition tracing api that weโ€™ve discussed before in labs posts. In our backlog.

from react.

phryneas avatar phryneas commented on July 27, 2024

Yeah, this is definitely not something that should hold React back. If things change, they change. This would just surface it.

The idea is more to ensure that if a new React version is released and one of our apis unexpectedly starts seeing additional renders, we can catch and fix that sooner rather than later.
It's definitely only targeted for a "testing" use case - which is also why I suggest something like a react-dom/test entrypoint.

from react.

eps1lon avatar eps1lon commented on July 27, 2024

Have you explored wrapping your tests in React.Profiler and asserting on the render callbacks? I explored that originaly in MUI. The idea was that we wrap every test in React.Profiler and track changes. It seemed promising but I didn't finish it with tracking numbers in a useful way (p90, diffs between commits, measurements over time etc).

You may want to check out if you get more accurate real world results by not using act in these tests.

Transition tracing would help for more detailed insights. Though maybe we can just expose the updater tracking React Devtools has already access to ("Why did this render?" in the Profiler panel).

from react.

phryneas avatar phryneas commented on July 27, 2024

Have you explored wrapping your tests in React.Profiler and asserting on the render callbacks?

We kinda do - we wrap the tests in React.Profiler, and on every onRender callback, we create snapshots of the DOM and additional test-specific additional values (hook return values etc.).
We just don't immediately make assertions, but we save these values to the side, to make assertions on them at another time.

You may want to check out if you get more accurate real world results by not using act in these tests.

Now I'm intrigued - isn't the advice to use act to get more real world results?

Though maybe we can just expose the updater tracking React Devtools has already access to

Yes, please, let's start small - perfect is the enemy of "at all", and there is a ton of data currently available to the DevTools that we cannot access from tests right now. Getting access to these would already be incredible, we don't need anything beyond that right now!

from react.

eps1lon avatar eps1lon commented on July 27, 2024

We kinda do - we wrap the tests in React.Profiler, and on every onRender callback, we create snapshots of the DOM and additional test-specific additional values (hook return values etc.).
We just don't immediately make assertions, but we save these values to the side, to make assertions on them at another time.

So you're not actually interested in profiling but making more granular assertions. I think you just want to test without act to assert on the intermediated steps not profiling tools.

Now I'm intrigued - isn't the advice to use act to get more real world results?

act() flushes everything scheduled before it exits. That's not necessarily what you'll see in real world applications e.g. React receives mousemove events it may batch the state updates into a single commit. If you wrap both in act, you'll always get two commits.

Yes, please, let's start small - perfect is the enemy of "at all", and there is a ton of data currently available to the DevTools that we cannot access from tests right now. Getting access to these would already be incredible, we don't need anything beyond that right now!

Except these have holes and bugs at the moment. Transition tracing is still in progress so we shouldn't just expose updater tracking just that we have something. There is a cost to shipping unfinished things at React's scale. If it doesn't work out, there's a lot of work required to remove it holding back the ecosystem. This works in internal repos like at Meta since you have direct access but doesn't scale to the ecosystem with unknown priorities and motivations.

from react.

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.