Closed dlindahl closed 10 months ago
Nice catch. Thanks for reporting.
Would you or anyone like to fix it? derive
is already complicated, and hope to simplify the implementation.
Here's a new proposition, which might be controversial: #792
Transferred to: https://github.com/valtiojs/derive-valtio/issues/1
Summary
Calling
underive
withdelete: true
does not delete the derived property value unless there is a dependency.derive
subscribes to the dependencies defined within thederive
function.underive
withdelete: true
loops through all of the dependencies.Set
to delete later.proxyObject
.The problem arises from a situation where the derived function never calls
get
(for whatever reason) which prevents a subscription from being created. The lack of a subscription prevents the property from being deleted which then prevents new calls toderive
because the property is already defined.Is this silly? Yes. Was this hard to debug. Also yes. 😄
Property deletion should probably be decoupled from the existence of a subscription, especially since I see some async subscriptions being handled in the
derive
code which could possibly introduce a situation whereunderive
is called before the async value resolves which would result in a similar error.Link to reproduction
Pardon the lack of a codesandbox repro as the problem seemed pretty straight forward. I can make one if you really need one though.
Check List
Please do not ask questions in issues.
Please include a minimal reproduction.