// https://vike.dev/onRenderHtml import { renderToString as renderToString_ } from '@vue/server-renderer'; import { escapeInject, dangerouslySkipEscape } from 'vike/server'; import { createApp } from './app.js'; import getTitle from '../src/get-title.js'; async function renderToString(app) { let err; // Workaround: renderToString_() swallows errors in production, see https://github.com/vuejs/core/issues/7876 app.config.errorHandler = (err_) => { // eslint-disable-line no-param-reassign err = err_; }; const appHtml = await renderToString_(app); if (err) { throw err; } return appHtml; } async function onRenderHtml(pageContext) { const { Page, pageProps } = pageContext; // This onRenderHtml() hook only supports SSR, see https://vike.dev/render-modes for how to modify // onRenderHtml() to support SPA if (!Page) { throw new Error('My render() hook expects pageContext.Page to be defined'); } const app = createApp(Page, pageProps, pageContext); const appHtml = await renderToString(app); // See https://vike.dev/head const { documentProps } = pageContext.exports; const title = getTitle(documentProps?.title || pageContext.title); const desc = (documentProps && documentProps.description) || 'traxxx'; const documentHtml = escapeInject`