-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
play function does not work after React 18 #18258
Comments
Do you a have a reproduction repo you can share? If not, can you create one? See how to create a repro. Thank you! 🙏 |
@shilman and @yannbf Sorry for the delay. I created repo and story is under src directory. App.stories.js -> https://github.com/reinertisa/my-example-reproduction Thank you for your help. |
HI @reinertisa !! Thanks so much for creating a reproduction. However, I'm seeing the same behavior when I run your repro in both React 17 and 18: Can you please help clarify what I'm supposed to see differently? Also can you share the output of |
Hi @shilman I see your screenshot for React 18 but When I use React 17. I see this screenshot. (I see validation error as expected) |
@shilman this is output for my dev machine. Thank you for your help. System: |
@reinertisa Clearly I need more coffee this morning! ☕ Ok, I'm able to reproduce the issue now (though intermittently -- sometimes I see the validation error in React18 also!) Can you please update your story code like this and verify that the problem goes away? const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
export const Default = {
render: (args) => <App {...args} />,
play: async ({ canvasElement }) => {
await sleep(0);
await userEvent.click(within(canvasElement).getByRole('button', { name: /Submit/i }));
},
}; It's not a proper fix, but if it works for you that will help us diagnose the problem and work towards a proper solution. Thanks! |
@shilman Thank you for information but I used sleep function after we updated React 18 to see validation errors and it worked but after that our chromatic build failed. We are not sure this sleep function caused that problem. I hope you can find proper solution for it. I am looking forward to it. Also I need coffee. Enjoy ☕ |
@shilman maybe you need to see chromatic failure link for your reference. When I use sleep function, it works locally but fails in chromatic. I can provide link to failure for your reference. https://www.chromatic.com/test?appId=5eeab205fdb1e500227646e6&id=62b0bbe8c5862a6e55a3e9d8 |
Thanks so much @reinertisa. No idea what the problem is yet, but this is a great starting point! |
I can also confirm I'm experiencing this (or a very similar) issue after updating to react 18 (and storybook 7-alpha.33). I have the validation error problem as shown above, but also the first character is sometimes lost from await userEvent.type(input, '1234'); Results in Similarly, a "combobox" of mine is not opening correctly when first clicked on, unless I add a sleep. How does the play function know when to fire? IOW, where does storybook trigger the play function, and is there a chance that it needs to wait just a bit longer for react to finish rendering? |
This saved me today. Thanks! I'm also seeing this on my copy using react 18. |
I think that I have noticed smtg similar with the latest preact as well. I think Preact changed some of the internal (maybe related to 10.10). I will try to create a repro later when I have time (I am kind of lazily hoping that a preact update fixes it). |
@shilman is there a timeline for this fix? The workaround does help, but we've had to use |
I see that @yannbf is assigned to this ticket, I think he might be the best to discuss the plans for it. I do hope it can be fixed soon, since it's essentially blocking my upgrade to react 18 right now. |
I see, thanks. If I make the callback to |
Do we have something like |
Yes we can use that. Do you know what we could potentially trigger off of, though? |
|
Any updates on this? We just upgraded to react 18 and we are encountering this issue. We have a sleep(1000) for now, but it would be nice to have a proper fix. |
@sw-tracker if you have to sleep that long, it may be a different issue. I've found that sleeping for 1 ms is usually enough for this particular issue. I still haven't gotten to the root cause, and have resorting to sprinkling a few |
@IanVS sorry yes, |
Can someone provide a simple reproduction with the latest Storybook 7? Thank you so much <3 |
@yannbf I updated my reproduction above to 7.0.6: stackblitz.com/edit/github-z8cetq?file=src/reacthookform.jsx. |
@IanVS interestingly that reproduction itself is very intermittent--basically doesn't happen for me apart from the very first render. Would it be useful to put together a non-SB reproduction @bluebill1049? Have you tried that @IanVS? |
@IanVS do you know what the status is on this one? I'm wondering if we should close this issue as ultimately it doesn't seem like an issue with SB itself. |
I've resorted to sprinkling |
Ok, I had a play around with the reproduction on this issue outside of SB. I reproduced the behaviour with https://codesandbox.io/s/dry-fire-bmoc2t?file=/src/App.js cc @yannbf |
This would be great but I think testing library user event 14 was tested and reverted because of incompatibility, it would be great if this is now possible though! |
I have started to experience this after upgrading React 17 to 18. In our case we have a
Our test has the following which the element has
What is happening for us is that the user click event is happening before the useEffect has run when the component renders. Adding a sleep above solves the problem as the click will run after the useEffect has run. |
@shilman hi, today I updated storybook/testing-library (0.0.13 -> 0.2.0(latest)) and removed sleep function from play and all interactions triggered react-hook-form validations as expected locally. By the way we are still using storybook(6.5.16). Did you have any chance test this issue with latest storybook/testing-library(0.2.0) ? Maybe this is the solution. But when we tried to catch snapshot using chromatic, all snapshots are failed and this is the screenhot coming from chromatic build. |
Hey there! As mentioned a few times in this thread, it seems like the issue is with I would highly recommend you to upgrade to Storybook 7 if you can, not only because Storybook 6 is about 3 years old by now, but also because there were many fixes regarding the interactions addon and its relation to Here's a video comparing two repros, one that fails and the other one that does not: testing.library.issue.movI also noticed that your error does not seem to be the same as the ones mentioned in the reproduction: This error happens when people use |
@yannbf thank you for feedback. We want to update storybook but we have some problem about it and my teammate created an issue on storybook. Our story file config is like that. I do not import @testing-library/react in our story files.
|
@yannbf I talked to Chromatic team and they shared me reference issue #19758 about play function does not work in stories built for Production and when I read this issue a couple of reasons trigger this problem and for us, we changed our build commands and it worked and I will summarize it here for people who will have this problem in the future.
As a result, today we got our first successful chromatic build and play function trigger RHF(react-hook-form) validations without sleep fn. Thank you for helping to fix this issue. @shilman @tmeasday @IanVS @bluebill1049 @yannbf |
This solution is kind of hack so I will keep this issue open until we get latest storybook. |
Personally, I found that updating to the latest |
Thank you so much @reinertisa for trying all this out and providing information here! |
For those of you who are struggling for this issue:
This worked for me. |
**Describe the bug** I created stories for react-hook-form validation and used play function. It worked well React 17. After I updated React from 17 to 18, play function does not trigger validation. Do I miss something? @yannbf
Expected output
The text was updated successfully, but these errors were encountered: