Skip to content

Allow hooking into render context #14182

@pi0

Description

@pi0

Sometimes it is necessary (especially for module authors) to hook into the renderer and do modifications or access the rendered HTML outside of the app lifecycle (making it possible to extend for SPA mode as well and write code in server context). We can allow this using nitro plugins hooking into renderer. I'm proposing two new server/nitro hooks:

  • nuxt:render:rendered (context: NuxtRenderContext) (Allow the modification and extension to the render result before compiling the template. html is unset)
  • nuxt:render:html (html: string, context: NuxtRenderContext) (read-only access to final rendered html. modification is prohibited by design to avoid heavy string concatenation and preferring small context appending)

Notes:

  • Would worth to add ssrContext to RenderResult.
  • We might rename RenderResult interface to NuxtRenderContext before exposing
  • RenderResult.html type was never used. I'm proposing to remove it to make types less confusing.
  • We might introduce other types of render results (such as payload) in the future.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions