You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you share a store setter from an iframe to its parent and call it via the parent, objects assigned to the store via this method, will not be reactive.
. Different windows have different Object.prototype and therefore an object assigned via another window, will not be considered as wrappable by solid store.
Since the prototype check works as intended for normal non-iframe use cases, a sensible way would be to just allow a hook into the check, e.g. something like this:
registerWrappablePrototype would allow advanced developers to add parent/iframe Object.prototype, vice-versa.
Edit: Alternative: how about we use duck typing to figure out if proto is wrappable, if it quacks like a Object.prototype it must be one. We would just have to make sure that the duck typing works across realms.
The text was updated successfully, but these errors were encountered:
Yeah this is one of those annoying things. Forcing this into user space seems really awkward. We need to consider the general solution. This check is to prevent classes. I'm deep into rethinking stores right now. Maybe that constraint is not necessary. It is worth investigation.
I also looked a bit deeper regarding the runtime typing approach. Most isPlainobject solutions out there sadly just do it with Object.prototype - (wheres the iframe love 🤣?), but Lodash has a different solution, that works across realms from what I found (https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L12045): Their Ctor instanceof Ctor check filters out classes and funcToString.call(Ctor) == objectCtorString takes care of the rest. I wonder what this would mean for performance though 🤔..
Describe the bug
If you share a store setter from an iframe to its parent and call it via the parent, objects assigned to the store via this method, will not be reactive.
Your Example Website or App
https://stackblitz.com/edit/github-gerxph-42ncis?file=src%2Froutes%2Findex.tsx
Steps to Reproduce the Bug or Issue
createEffect(() => console.log(JSON.stringify(state))
Expected behavior
Objects assigned to a store via a different window should become reactive like any other object.
Screenshots or Videos
No response
Platform
Additional context
The reason why objects assigned this way will not be reactive, is the prototype check in
solid/packages/solid/store/src/store.ts
Line 75 in 4d824b0
Object.prototype
and therefore an object assigned via another window, will not be considered as wrappable by solid store.Since the prototype check works as intended for normal non-iframe use cases, a sensible way would be to just allow a hook into the check, e.g. something like this:
registerWrappablePrototype
would allow advanced developers to add parent/iframeObject.prototype
, vice-versa.Edit: Alternative: how about we use duck typing to figure out if
proto
is wrappable, if it quacks like aObject.prototype
it must be one. We would just have to make sure that the duck typing works across realms.The text was updated successfully, but these errors were encountered: