solid icon indicating copy to clipboard operation
solid copied to clipboard

inconsistent owner in Component function (production vs development build) result in out of order onCleanup

Open LiQuidProQuo opened this issue 2 years ago • 6 comments

Describe the bug

A component function owner is different between a dev and prod build

function MyComponent(){
     getOwner()   // <--  this is different between prod/dev builds.
                  //      in prod the owner is of the parent, in dev it is a new owner scope.
     return <></>
}

this inconsistency causes unexpected behavior, for example when using solid's onCleanup primitive

dev build playground image

production build playground

image

note: production build is working as designed, it is dev that alters the expectations

Your Example Website or App

.

Steps to Reproduce the Bug or Issue

see playground links for the difference between dev and prod

Expected behavior

it is expected that dev and prod will work similarly, in regard to owner scopes.

Screenshots or Videos

No response

Platform

.

Additional context

No response

related discussion of the issue https://discord.com/channels/722131463138705510/1075879661134942238

LiQuidProQuo avatar Feb 17 '23 06:02 LiQuidProQuo

If you're using the Vite plugin (or any plugin that is using Solid Refresh), this is by design. The reason is because Solid Refresh wraps the component into a memo managed by proxy HMR component. You're always going to get the owner that is provided by the memo.

edit: seems like the discord thread is referring to some other issue.

lxsmnsyc avatar Feb 17 '23 16:02 lxsmnsyc

Yeah, the issue is mostly about the order of onCleanup calls in dev vs prod. Probably should be titled better.

thetarnav avatar Feb 17 '23 17:02 thetarnav

yes, onCleanup is one of the bug we know of that is caused by this extra wrapping in this case, is it the dev wrapper that is added in dev build, but it is very much possible that the hmr wrapper will cause similar issues, so it is perhaps something to consider when designing a general fix for this.

LiQuidProQuo avatar Feb 17 '23 19:02 LiQuidProQuo

I guess the fix is to exempt it as an owner. Have the parent still own everything. That seems doable.

ryansolid avatar Feb 19 '23 07:02 ryansolid

@thetarnav and I looked into possible fixes, we tested this as a fix what I did is resolve the parent if the component is marked as a dev component. then restore the owner at the end.

image

isHMROwner => isDevOwner

I did a minimal in browser patching, and it seem to correct the order with the very basic use case. I am not sure if onCleanup is the only place we want/need this, but it is a start

LiQuidProQuo avatar Feb 19 '23 09:02 LiQuidProQuo

I was playing around with something similar. At first I simply tried to hoist up the owner in devComponent, but obviously that would break DevTools. The whole point is to inject the owner.

Was this approach enough to get back out... because if I remember HMR also wraps things.. is it a Memo or Signal? If it is a signal that is fine. But if it is a Memo then we have another owner in here.

ryansolid avatar Feb 20 '23 04:02 ryansolid