fix(app, nitro): fix app:rendered hook (#53)

Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
Daniel Roe 2021-04-06 10:26:53 +01:00 committed by GitHub
parent 07e70ac35a
commit 7f97015c74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

View File

@ -13,12 +13,12 @@ async function initApp () {
await applyPlugins(nuxt, plugins) await applyPlugins(nuxt, plugins)
await applyPlugins(nuxt, clientPlugins) await applyPlugins(nuxt, clientPlugins)
await app.$nuxt.hooks.callHook('app:created', app) await nuxt.hooks.callHook('app:created', app)
await app.$nuxt.hooks.callHook('app:beforeMount', app) await nuxt.hooks.callHook('app:beforeMount', app)
app.mount('#__nuxt') app.mount('#__nuxt')
await app.$nuxt.hooks.callHook('app:mounted', app) await nuxt.hooks.callHook('app:mounted', app)
await nextTick() await nextTick()
nuxt.isHydrating = false nuxt.isHydrating = false
} }

View File

@ -12,11 +12,7 @@ export default async function createNuxtAppServer (ssrContext = {}) {
await applyPlugins(nuxt, plugins) await applyPlugins(nuxt, plugins)
await applyPlugins(nuxt, serverPlugins) await applyPlugins(nuxt, serverPlugins)
await app.$nuxt.hooks.callHook('app:created', app) await nuxt.hooks.callHook('app:created', app)
nuxt.hooks.hook('vue-renderer:done',
() => nuxt.hooks.callHook('app:rendered', app)
)
return app return app
} }

View File

@ -41,6 +41,11 @@ export async function renderMiddleware (req, res) {
...(req.context || {}) ...(req.context || {})
} }
const rendered = await renderer.renderToString(ssrContext) const rendered = await renderer.renderToString(ssrContext)
if (ssrContext.nuxt.hooks) {
await ssrContext.nuxt.hooks.callHook('app:rendered')
}
// TODO: nuxt3 should not reuse `nuxt` property for different purpose! // TODO: nuxt3 should not reuse `nuxt` property for different purpose!
const payload = ssrContext.payload /* nuxt 3 */ || ssrContext.nuxt /* nuxt 2 */ const payload = ssrContext.payload /* nuxt 3 */ || ssrContext.nuxt /* nuxt 2 */