Skip to content

Offcanvas component doesn't unmount when dismissed. #45

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

Closed
sid1029 opened this issue Feb 18, 2025 · 2 comments
Closed

Offcanvas component doesn't unmount when dismissed. #45

sid1029 opened this issue Feb 18, 2025 · 2 comments

Comments

@sid1029
Copy link

sid1029 commented Feb 18, 2025

I'm using the Offcanvas component like the following :

....
<Offcanvas
	style={{ '--bs-offcanvas-height': '60vh' }}
	scroll={false}
	placement='bottom'
	show={isDrawerOpen()}
	onHide={() => setIsDrawerOpen(false)}
>
	<Offcanvas.Body class={styles.myOffcanvasBodyStyles}>
		<MyComponent />
	</Offcanvas.Body>
</Offcanvas>

I am using onMount and onCleanup lifecycle hooks inside MyComponent.
If I open and dismiss the offcanvas drawer repeatedly, I notice the onMount hook firing on every open. But the onCleanup hook doesn't fire on every dismiss. It only fires when I route away from the entire page.
And it fires multiple instances of onCleanup (equal to the number of times I opened the modal), which means each instance of opening the Offcanvas is mounting a new component and it stays around, never getting cleaned up until we leave the page.

This is a memory leak and leads to a laggy UI after a while of normal usage (which involves many opening/closings of the Offcanvas).

@Brendan-csel
Copy link
Collaborator

Thanks for reporting this. Let me know if 1.0.21 doesn't help.

@sid1029
Copy link
Author

sid1029 commented Mar 14, 2025

Thanks for addressing this !
The fix does seem to work correctly. I've got the new behavior working in a minimal sample here - See console logs for Home mounted / unmounted.

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

2 participants