Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
It would be very convenient to have a built-in way of adding a cleanup function from the scope of a function given to onMount, given that whatever variables are allocated in this scope, likely are tied to the component's lifespan.
I, personally, am doing some networked pub/sub, and sure, I could createSignal and allocate the subscription reference within the component as such, but I'd much rather be able to simply go "return () => server.unsubscribe(ref)" from within the function given to onMount itself.
How did you test this change?
I've yet to get pnpm working, but I'll try and add on some tests when I get it up and running. It might be some months before I get time for that though. If anyone has some minutes to spare and know how to test this in the first place, feel free to help me out.
From a statick analysis perspective, this code does not add anything new, nor does it expand on existing features. Its but an if statement and a type change. Taking a real "devils advocate" look on it, it does slightly increase memory cost for any function given to onMount, as it wraps the given function in order to extract and register the cleanup function (if any). However I currently do not know the solid code base well enough to know if there's a better alternative.