Skip to content
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

ListBox: crash when item clicked by playwright #6924

Closed
avasuro opened this issue Jul 25, 2024 · 0 comments · Fixed by #6925
Closed

ListBox: crash when item clicked by playwright #6924

avasuro opened this issue Jul 25, 2024 · 0 comments · Fixed by #6925
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@avasuro
Copy link
Contributor

avasuro commented Jul 25, 2024

Describe the bug

Problem

We use Playwright to run automated tests on our UI, and when Playwright "clicks" on a ListBox item, an error Cannot read properties of null (reading 'querySelector') appears.

This error occurs in the PrimeReact source code, approximately in components/lib/listbox/ListBox.js around line 482.

The reason for this issue is that Playwright, like any other automated testing tool, performs actions very quickly. During the "click" operation, it does the following:

  • Triggers mouseenter, mouseover, and mousemove events over the ListBox item that is going to be clicked.
  • Then it clicks on this item.

If the ListBox has focusOnHover={true}, after the "mousemove" event is triggered, PrimeReact internally schedules a "scroll hovered item into view" operation (using setTimeout with zero delay). Then Playwright quickly triggers the "click" event on this item, which causes the item to become selected, and our popup with the ListBox inside disappears/unmounts (this is our custom logic).

As a result, when the scheduled "scroll hovered item into view" operation runs, there is no listboxRef.current reference defined (since the component has already unmounted), and the code fails with an error.

Possible solution

Inside the setTimeout function, check if listboxRef.current still exists OR cancel timeout when component unmounts.

Reproducer

https://codesandbox.io/s/primereact-listbox-crash-v6r6rc

This one sometimes allows to reproduce this bug. In this example I tried to reproduce +- same behavior as happens in Playwright. To reproduce do the following:

  • click on "refresh" button (to do full page reload)
  • immediately after that quickly move mouse pointer in the area where listbox is displayed (preferrable: if you will be able to move mouse pointer before listbox is rendered)
  • after listbox is displayed - move mouse pointer over any of it's items

As result you should see an error. If error doesn't appears - click on "refresh" button again and repeat steps above. For me it reproduces approximately 6-8 times from 10 attempts.

PrimeReact version

10.7.0

React version

18.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@avasuro avasuro added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jul 25, 2024
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jul 25, 2024
@melloware melloware added this to the 10.7.1 milestone Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants