History: Uncaught DOMException: Failed to execute 'pushState' on 'History': function (data) { } could not be cloned.

Created on 5 Jan 2018  路  5Comments  路  Source: ReactTraining/history

Question? bug?

recently I migration history V1.13.0 to V4.7.2 , i got an error when i use history.push .
more detail see below :

reason: some param in the state is a method

code: history.push('/abc',{callback: () => {// done something});

error:

Uncaught DOMException: Failed to execute 'pushState' on 'History': function (data) {
// done something } could not be cloned.

this problem never found in V1.13.0

there are other ways to solve this problem?

thanks advance

Most helpful comment

All 5 comments

@keith890303 Did you manage to fix this? I'm having the same issue.

It looks like history v1.3.0 used sessionStorage, which apparently will serialize a function. However, from what I can tell, you would have had to parse the function yourself in order to run it. I guess I am a bit confused on _why_ you would want to store a function. Why not just store any arguments in state and call the function?

Any solution for functions in state? I'm having this problem for any function that I pass as state

I got this error when trying to add state (object) which contained something it didn't like. The data actually represented a caught error so in certain cases it worked and others it wasn't serializable (or whatever is needed).

I solved it using https://www.npmjs.com/package/safe-json-stringify which can serialize something even if it has functions or circular references. For error handling this was exactly what I wanted - a guarantee that the caught string could be serialized as best as possible.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clayrisser picture clayrisser  路  4Comments

dehghani-mehdi picture dehghani-mehdi  路  6Comments

saadbinsaeed picture saadbinsaeed  路  8Comments

johnjesse picture johnjesse  路  6Comments

govizlora picture govizlora  路  5Comments