Skip to content
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

Allow providing custom JSON stringify functions in SSR state serialization #6614

Closed
mapleeit opened this issue Sep 15, 2017 · 3 comments
Closed

Comments

@mapleeit
Copy link

Version

2.3.4

Reproduction link

https://jsfiddle.net/mapleeit/dnh0zpy8/

Steps to reproduce

SSR will use JSON.stringify method stringify initial state to window.__INITIAL_STATE__
but this initial state has circular quote which will throw error like TypeError: Converting circular structure to JSON

Is there any way to avoid this, or only thing I can do is to remove this circular state?

What is expected?

use something like [Circular] to avoid throwing error

What is actually happening?

TypeError: Converting circular structure to JSON


It's not convenient to make minimal reproduction on JSFiddle because of the webpack step.

@yyx990803
Copy link
Member

yyx990803 commented Sep 15, 2017

Currently there's no way around this.

I suggest "normalizing" your data structure with something like https://github.com/paularmstrong/normalizr

Another solution would be to provide an API to customize the stringifying function so that you can use something like https://github.com/WebReflection/circular-json or https://github.com/yyx990803/circular-json-es6 (note you'd also need to use them to parse the stringified state on the client)

@mapleeit
Copy link
Author

mapleeit commented Sep 18, 2017

@yyx990803 thanks for reply.

I'd like to use the second circular-json solution because there is a lot of work to "normalizing" our existing data structure.

But there is no API to use custom stringify function to serialize initial state? I found it uses serialize-javascript now.

So I'm eager for your suggestion for using the circular-json solution.

@yyx990803 yyx990803 changed the title Encounter JSON.stringify circular error when the initial state has circular quote using Vue SSR Allow providing custom JSON stringify functions in SSR state serialization Nov 20, 2017
@vuejs vuejs deleted a comment from dongnaebi Oct 7, 2018
@vuejs vuejs deleted a comment from beliefgp Oct 7, 2018
@yyx990803 yyx990803 added this to Todo in 2.6 Dec 6, 2018
@yyx990803 yyx990803 moved this from Todo to In progress in 2.6 Dec 20, 2018
yyx990803 added a commit that referenced this issue Dec 20, 2018
@yyx990803
Copy link
Member

Closed via 4494012

2.6 automation moved this from In progress to Done Dec 20, 2018
f2009 pushed a commit to f2009/vue that referenced this issue Jan 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
2.6
  
Done
Development

No branches or pull requests

2 participants