Static GitHub Issues

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

prev: Hoek version
next: How to import scss file without specify extension in nuxt inside vue template file?

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 }) => {
})
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This feature request is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c7015">#c7015</a>)</em></sub></div>