Skip to content

Offcanvas component doesn't unmount when dismissed. #45

Closed
@sid1029

Description

@sid1029

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions