diff --git a/packages/playwright-ct-react17/registerSource.mjs b/packages/playwright-ct-react17/registerSource.mjs index 1c484b2b12..50a888b92a 100644 --- a/packages/playwright-ct-react17/registerSource.mjs +++ b/packages/playwright-ct-react17/registerSource.mjs @@ -86,6 +86,8 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => { window.playwrightUnmount = async rootElement => { if (!__pwReactDOM.unmountComponentAtNode(rootElement)) throw new Error('Component was not mounted'); + + __pwRootRegistry.delete(rootElement); }; window.playwrightUpdate = async (rootElement, component) => { diff --git a/tests/components/ct-react-vite/tests/unmount.spec.tsx b/tests/components/ct-react-vite/tests/unmount.spec.tsx index 20374d8b8e..4ce2d45889 100644 --- a/tests/components/ct-react-vite/tests/unmount.spec.tsx +++ b/tests/components/ct-react-vite/tests/unmount.spec.tsx @@ -23,3 +23,10 @@ test('unmount twice throws an error', async ({ mount }) => { await component.unmount(); await expect(component.unmount()).rejects.toThrowError('Component was not mounted'); }); + +test('mount then unmount then mount', async ({ mount }) => { + let component = await mount(