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

Add a hook which is passed context for testing the state data passed from server to client #3294

Closed
38elements opened this issue May 3, 2018 · 8 comments

Comments

@38elements
Copy link

38elements commented May 3, 2018

What problem does this feature solve?

I want to test the state data passed from server to client.
This resolve this by adding a hook to get context.nuxt.

What does the proposed changes look like?

https://github.com/nuxt/nuxt.js/blob/8feeeb0cfe4345e47f561198272ded6926d8d2b8/lib/core/renderer.js#L355-L361

    const serializedSession = `window.__NUXT__=${serialize(context.nuxt, {
      isJSON: true
    })};`

    await this.nuxt.callHook('render:passingData', context.nuxt)

    const cspScriptSrcHashes = []
    if (this.options.render.csp && this.options.render.csp.enabled) {

Usage

const { Nuxt, Builder } = require('nuxt')
const config = require('./nuxt.config.js')
config.dev = false
const nuxt = new Nuxt(config)
nuxt.hook('render:passingData', (passingData) => {console.dir(passingData)})
new Builder(nuxt)
.build()
.then(() => nuxt.renderRoute('/'))
.then(({ html, error, redirected }) => {
})
This feature request is available on Nuxt.js community (#c7015)
@ghost ghost added the cmty:feature-request label May 3, 2018
@Atinux
Copy link
Member

Atinux commented May 3, 2018

Hi @38elements

I like this idea, I'm not found of passingData, why not calling it render:context (cc @pi0 @clarkdo)

@pi0
Copy link
Member

pi0 commented May 3, 2018

I love this idea too! Indeed we can do many more things than just for testing. Also, render:context hook seems more clear :)

@Atinux
Copy link
Member

Atinux commented May 3, 2018

Why not calling it before serializedSession so it gives the opportunity to modules to extend the data sent back (even if we have beforeNuxtRender method already)?

@clarkdo
Copy link
Member

clarkdo commented May 3, 2018

It's indeed a good proposal, I aggree with @Atinux 's opinion, I can try to add it this evening.

@syffs
Copy link

syffs commented May 3, 2018

Could this help to overcome such persisted vuex issues?

@38elements
Copy link
Author

38elements commented May 4, 2018

Thank you for reply.

I think render:context is better.

Why not calling it before serializedSession so it gives the opportunity to modules to extend the data sent back (even if we have beforeNuxtRender method already)?

This is very good idea.
This creates many possibilities.
For example, This makes it possible to test only for client side by setting context data at the render:context hook.

@38elements
Copy link
Author

I am sorry.
I misunderstood about nuxt.renderRoute().

@lock
Copy link

lock bot commented Nov 2, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants