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

Immediate close of an open lightbox with escape button leaves portal in DOM #6

Open
amalitsky opened this issue Nov 29, 2024 · 0 comments

Comments

@amalitsky
Copy link

Describe the bug

I'm writing Playwright test for the updated lightbox and came across a situation when closing lightbox with escape button causes portal to stay in the DOM with portal_closed class attached.

Simplified test code:

lightboxOverlay = page.locator(LightboxSelector.host);

await expect(lightboxOverlay).toBeVisible();

await page.keyboard.press('Escape');

await expect(lightboxOverlay).toBeHidden();

Test fails, because lightboxOverlay remains in a visible state.

Once this happens, portal stays in the DOM with portal_closed class attached for at least 30 seconds. No exceptions in DevTools console. Adding wait after await page.keyboard.press('Escape') doesn't help, while adding wait before it does solve the problem.

As a side note - by playwright's standards opacity: 0 is considered a visible state. Hence changing assertion to await lightboxOverlay.waitFor({ state: 'hidden' }) doesn't work either.

There seems to be a race condition between react useEffect and promise-based cleanup hooks, but I couldn't pin point the actual problem.

Also I doubt this can be observed by a normal user, only test automation can catch it.

Expected behavior

Expected behavior is for portal to get removed from the DOM after having portal_closed class for a split second.

Test closing portal with a Close button click works just fine:

lightboxOverlay = page.locator(LightboxSelector.host);

await expect(lightboxOverlay).toBeVisible();

const closeButton = lightboxOverlay.locator(LightboxSelector.closeButton);

await closeButton.click();

await expect(lightboxOverlay).toBeHidden();

I assume this is because PW uses additional checks for a clickable element, which lead to additional wait seemingly preventing race condition from happening.

How to reproduce

I'll look for options to have an online PW test sandbox.

I don't think end user will ever face this situation.

Screenshots / Logs

Terminal state of the failing state.
Screenshot from 2024-11-29 08-30-43

Additional context

This bug could be caused by the way my application is built and bootstrapped.
Also, PW tests are prone to race-conditions which are hard to debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant