Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt)!: allow app:rendered to modify ssr context and add render:html #6521

Merged
merged 6 commits into from
Aug 11, 2022

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Aug 11, 2022

πŸ”— Linked issue

Resolves nuxt/nuxt#14537

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • [x 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

We were calling app:rendered hook just after ssr rendering is being done in Nuxt 3 <= 3.0.0-rc.6. #6042 changed this behavior in v3.0.0-rc.7 that app:rendered is being called with new rendered context to have access to constructed html but this means, it is too late to modify payload.

This PR reverts app:rendered back to previous behavior with new limited { ssrContext } context only. (breaking change)

Nitro plugins have access to the final rendered context via render:html (breaking change: nuxt:app:rendered renamed for nitro plugins to be simpler, consistent with render:response hook and not confused with app:rendered lifecycle hook)

Example usage: (nitro plugin)

// server/plugins/render.ts
export default defineNitroPlugin((nitroApp) => {
  nitroApp.hooks.hook('render:html', (html, { event }) => { console.log({ html }) })
  nitroApp.hooks.hook('render:response', (response, { event }) => { console.log(response) })
})

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented Aug 11, 2022

βœ… Deploy Preview for nuxt3-docs canceled.

Name Link
πŸ”¨ Latest commit cd24408
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/62f5232c6cc9d600087a247a

@pi0 pi0 requested a review from danielroe August 11, 2022 15:13
@pi0 pi0 changed the title fix(nuxt)!: allow app:rendered hook to modify ssr context fix(nuxt)!: allow app:rendered to modify ssr context and add render:html Aug 11, 2022
@pi0 pi0 mentioned this pull request Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ssrContext effectively read-only in app:rendered hook 3.0.0-rc.7
3 participants