-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
StoreDevtools: window postMessage, object Position cannot be cloned #825
Comments
Fixed. But i would let open this issue, because it is interesting problem. Maybe it relates to some problem.. If i create an observable from window.geolocation.getPosition() and pass Position object from the callback directly to observer. it will crash in navigation in StoreDevTools. However. if i map that position to my own new object, it works.. ` OK it looks like StoreDevTools is trying to copy the object when it is already freed:? Feel free to close the issue |
What is the fix here? I'm getting an error like this too. |
WELL... do not use Position object from geolocation callback directly in your code.. Just copy Longtitude, lattitude values to new object.
BTW-... this wasnt the only one problem we had.. We had to remove ALL "Position" type in our code, else we got "Position is undefined" error in runtime - lol.. I think there may be problem in Typescript lib.dom.ts where are Position 2times: as a interface and as a value. |
ok. looks like this is not the same issue for me! But when i disable the Below is the error message I get:
|
Well.. this looks littlebit like your own mistake, are you pushiung to observer a component? |
same issue if redux extension is on after updating from to 5.1.0 works like a charm after downgrading version back |
@Overdozed same thing happened to me. but after execute $ yarn info @ngrx/effects The version |
@Overdozed any fix? |
Can someone post a reproduction using stackblitz? |
@brandonroberts for now I will attach the proper error message here. I will get this error message only when Redux devtool extension is enabled on Chrome and only if I executing the action this.store.dispatch(new fromRoot.Go({
path: ['11', '66'],
extras: {
relativeTo: this.route
}
})); |
The structured clone algorithm [1] which is used by The error is ease to reproduce by the following: const a = {
abc () {}
};
window.postMessage(a, '*') [1] https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm |
In my case the |
There are two things contributing to this issue. Before #790 landed, the serialize option was set to false, handling circular references (such as those provided if you dispatch an action with the My recommendation is that if you're dispatching actions with the |
@brandonroberts could u please share a possible usage code with |
@brandonroberts after few hours, I think I figured it out! works like charm 👍 |
@warapitiya cool. Will you share what you came up with? Would be good to reference in this issue and something we could look at adding to the docs. |
I just add StoreDevtoolsModule.instrument({
maxAge: 25, // Retains last 25 states
actionSanitizer: (action: { type: string; payload?: any }, id: number): Action => action.type === '[Router] Go' && action.payload ?
{...action, payload: '<<LONG_BLOB>>'} : action
}), |
I actually went with a similar, but smaller solution since it wasn't entirely clear for me which action was causing the issue: StoreDevtoolsModule.instrument({
maxAge: 25,
actionSanitizer: action => JSON.parse(stringify(action))
}) Only issue I can think of with this approach is circular references, but I have yet to encounter that. EDIT: To make it sturdy enough to handle circular references I added the follow wrapper for JSON.stringify: export function stringify(obj: any, replacer?, spaces?, cycleReplacer?): string {
return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
}
function serializer(replacer, cycleReplacer) {
const stack = [];
const keys = [];
if (cycleReplacer == null) {
cycleReplacer = (key, value) => {
if (stack[0] === value) {
return '[Circular ~]';
}
return `[Circular ~.${keys.slice(0, stack.indexOf(value)).join(".")}]`
}
}
return function (key, value) {
if (stack.length > 0) {
const thisPos = stack.indexOf(this);
~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
if (~stack.indexOf(value)) {
value = cycleReplacer.call(this, key, value);
}
} else {
stack.push(value)
}
return replacer == null ? value : replacer.call(this, key, value)
}
} The above is a shameless steal of the package json-stringify-safe, but adapted to typescript. |
@wesselvdv cool. I know the devtools extension uses https://github.com/kolodny/jsan underneath for serialization that supports circular references and such. |
Anyway, I noticed when serializing there is a significant performance hit. |
I have been receiving the same error. (Error message below) and have narrowed it down to occurring when the
Interestingly if I sanitise all actions to a simple object with only the type attribute, the error doesn't occur. eg:
It is occurring when a lazily-loaded redux store is injected. Error Message
|
Had a similar error, but after upgrading to 5.2.0 the error is gone, I think this commit fixed it: a5dcdb1 |
I'm still getting this error on 5.2.0, exact same problem as @jmannau. Any solutions? |
@tmonte apologies for the late reply. I used an ActionSantizer as per #825 (comment) to remove the action payload that caused the error. In my case, there were 2 actions that had payloads that error on serialisation. One had a My ActionSanitizer is the following:
|
Hi guys !
StoreDevtoolsModule.instrument({
maxAge: 10,
stateSanitizer: (oriState: any, id: number): any => {
const { router, ...newState } = oriState;
const { state, ...newRouter } = router || { state: null };
const { _root, ...newRouterState } = state || { _root: null };
return {
...newState,
router: {
...newRouter,
state: newRouterState
}
};
}
}) In my case, i removed _root from the router state object, because it contained a circular importation ! |
I'm submitting a...
[x ] Bug report
What is the current behavior?
Just migrated to the newest typescript and we got new error from StoreDevTools.
"window postMessage, object Position cannot be cloned"
The text was updated successfully, but these errors were encountered: