-
-
Notifications
You must be signed in to change notification settings - Fork 924
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
Circular references in Stores trigger loss of proxying if non-trackable objects are referenced #2056
Comments
in proxyTraps, if I remove the unwrap here, the bug is fixed. |
You don't want to remove that unwrap because you don't want to directly set proxy instances on the proxied object directly, if you can easily avoid it, the problem is how the |
This happens because changing This wouldn't happen if const makePerson = (name: string) => {
const dogs = createMutable<Array<Dog>>([]);
return {
name,
dogs
};
}; this would work: const makePerson = (name: string) => {
return createMutable<Person>({
name,
dogs: []
});
}; But also I think your code could work if unwrapping skipped original proxy, so if proxy trap was something like this: set(target, property, value, receiver) {
batch(() => setProperty(target, property, unwrap(value, new Set([receiver]))));
return true;
} (this should affect only circularly referenced proxies) |
So actually I checked, and my suggestion to change proxy trap wouldn't work.
when adding new dog with owner, the proxy would be assigned to original value and then unwrapping wouldn't handle proxy within proxy. So my suggestion is to avoid controlling mutable only from within non-trackable object as it can become non-trackable itself. const mutable = createMutable({});
const onClick = () => mutable.prop = ... // this is fine const mutableWrapper = { mutable: createMutable({}) };
const onClick = () => mutableWrapper.mutable.prop = ... // not using mutable directly, avoid this const mutableWrapper = createMutable({ mutable: createMutable({}) })
const onClick = () => mutableWrapper.mutable.prop = ... // this is also fine |
@maciek50322 , thanks so much for digging into this! So the problem isn't with circular references, it's with circular references outside of stores... (I modified my original playground from discord that used Store instead of Mutable, https://playground.solidjs.com/anonymous/8f07d9c2-54da-43e9-8e08-88393f446bca, to make everything a Store and that works now, which seems to confirm it: https://playground.solidjs.com/anonymous/4d5e0561-8504-4093-be33-b80a08ab02f0) While this is fine as a workaround, I'm assuming this would still be considered a bug, as I may want to use plain objects instead of stores in some cases. I'll change the issue description accordingly. |
Update
This issue originally suggested that circular references in stores triggered loss of proxying, but after further investigation by @maciek50322 , it turns out that the issue is when mixing non-trackable objects with trackable ones (as in the playground examples below). I think this is still a bug, as we may want to store Stores inside of plain objects with circular references.
Original issue:
Describe the bug
(From Discord support channel here with more investigation details. Was told to file here as a bug)
Solid Playground:
Notice in the playground that we can add as many dogs who don't know their trainers, but only one dog which knows its trainer (which has a circular reference on the dogs they are training)
As someone new to Solid, my understanding of the investigation from Discord is that when adding an object to a list in a store which creates a circular reference, the proxy object seems to be lost in
unwrap
, leading the list to update with the circular reference the first time, but then never be updatable afterwards.Your Example Website or App
https://playground.solidjs.com/anonymous/8f3ae147-b722-4b67-8592-044670933b61
Steps to Reproduce the Bug or Issue
Expected behavior
As a user I expected to be able to add as many circular references as I want.
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: