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

onMount/onCleanup not based on when component is added-to/removed-from DOM #2354

Open
ZeikJT opened this issue Nov 2, 2024 · 1 comment
Open

Comments

@ZeikJT
Copy link

ZeikJT commented Nov 2, 2024

Describe the bug

If you store a component in a variable it runs onMount once the element is created, but not necessarily when it's mounted to the actual DOM. If this isn't fixable, might want to update the docs.

Similarly for onCleanup, once you're in this state the cleanup is based on the ancestors.

Your Example Website or App

https://playground.solidjs.com/anonymous/dbcc36b4-44e6-49ed-a7bf-50e376d71016

Steps to Reproduce the Bug or Issue

https://playground.solidjs.com/anonymous/dbcc36b4-44e6-49ed-a7bf-50e376d71016
https://playground.solidjs.com/anonymous/efd63022-a8c2-44fb-842f-51c474b4b959

Expected behavior

As a user, I'd expect onMount and onCleanup to run when the relevant component and elements are inserted into and removed from the DOM itself.

Registers a method that runs after initial rendering is done and the elements are mounted to the page.

https://docs.solidjs.com/reference/lifecycle/on-mount (emphasis mine)

Screenshots or Videos

No response

Platform

All of them I'd assume

Additional context

No response

@MateuszDev96
Copy link

From the way I understand how solid-js works, this onMount and onCleanup means more that the component has been plugged into a reactive core than into an actual document. I also find it confusing and ambiguous because, for example, web-components has a host element and a callbacks connectedCallback and disconnectedCallback and this actually says whether this component is mounted or not. In your case you are calling JSX at the level of the App function and as long as it is there then onCleanup will not execute for you.

This might interest you https://github.com/solidjs-community/solid-primitives/tree/main/packages/lifecycle#onelementconnect

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