From cacf7b5b8d3c7ed578242eb4a5f6b408968e588f Mon Sep 17 00:00:00 2001 From: schneefux Date: Mon, 11 Dec 2023 08:25:54 +0100 Subject: [PATCH] Revert "web: Migrate to vike v1 paths" incompatible with error page setup This reverts commit cacf7d215154edb5ef6b42ddac8a853c63859299. --- web/pages/_error/+config.h.ts | 7 --- web/pages/_error/+onRenderClient.ts | 9 --- web/renderer/+config.h.ts | 13 ---- web/renderer/+onRenderHtml.ts | 51 --------------- web/renderer/_error.page.client.ts | 9 +++ .../_error.page.server.ts} | 13 +++- .../+Page.vue => renderer/_error.page.vue} | 4 +- ...{+onRenderClient.ts => all.page.client.ts} | 4 +- web/renderer/{+route.ts => all.page.route.ts} | 0 ...{+onBeforeRender.ts => all.page.server.ts} | 62 +++++++++++++++++++ web/renderer/{+Page.vue => all.page.vue} | 0 web/{pages/_error => renderer}/error-app.ts | 4 +- 12 files changed, 87 insertions(+), 89 deletions(-) delete mode 100644 web/pages/_error/+config.h.ts delete mode 100644 web/pages/_error/+onRenderClient.ts delete mode 100644 web/renderer/+config.h.ts delete mode 100644 web/renderer/+onRenderHtml.ts create mode 100644 web/renderer/_error.page.client.ts rename web/{pages/_error/+onRenderHtml.ts => renderer/_error.page.server.ts} (78%) rename web/{pages/_error/+Page.vue => renderer/_error.page.vue} (79%) rename web/renderer/{+onRenderClient.ts => all.page.client.ts} (95%) rename web/renderer/{+route.ts => all.page.route.ts} (100%) rename web/renderer/{+onBeforeRender.ts => all.page.server.ts} (52%) rename web/renderer/{+Page.vue => all.page.vue} (100%) rename web/{pages/_error => renderer}/error-app.ts (88%) diff --git a/web/pages/_error/+config.h.ts b/web/pages/_error/+config.h.ts deleted file mode 100644 index e334bada..00000000 --- a/web/pages/_error/+config.h.ts +++ /dev/null @@ -1,7 +0,0 @@ -export default { - passToClient: [ - 'errorWhileRendering', - 'errorMessage', - 'statusCode', - ], -} diff --git a/web/pages/_error/+onRenderClient.ts b/web/pages/_error/+onRenderClient.ts deleted file mode 100644 index 8feee60b..00000000 --- a/web/pages/_error/+onRenderClient.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { createApp } from './error-app' -import type { PageContext } from '../../renderer/types' - -export { onRenderClient } - -async function onRenderClient(pageContext: PageContext) { - const params = createApp(pageContext) - params.app.mount('#app') -} diff --git a/web/renderer/+config.h.ts b/web/renderer/+config.h.ts deleted file mode 100644 index 44d91513..00000000 --- a/web/renderer/+config.h.ts +++ /dev/null @@ -1,13 +0,0 @@ -export default { - passToClient: [ - 'vueQueryState', - 'piniaState', - 'errorWhileRendering', - 'envConfig', - 'validated', - 'statusCode', - 'redirectTo', - 'refs', - 'localeMessages', - ], -} diff --git a/web/renderer/+onRenderHtml.ts b/web/renderer/+onRenderHtml.ts deleted file mode 100644 index 064437fb..00000000 --- a/web/renderer/+onRenderHtml.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { renderToString } from '@vue/server-renderer' -import { dangerouslySkipEscape, escapeInject } from 'vike/server' -import { createApp } from './app' -import type { PageContext } from './types' -import type { PageContextBuiltInServer } from 'vike/types' -import { dehydrate } from '@tanstack/vue-query' -import { renderSSRHead } from '@unhead/ssr' -import SuperJSON from 'superjson' - -export { onRenderHtml } - -async function onRenderHtml(pageContext: PageContextBuiltInServer & PageContext) { - const { app, head, pinia, router, queryClient } = createApp(pageContext) - - let firstError: unknown = undefined - app.config.errorHandler = (err) => { - firstError = firstError ?? err - return false - } - router.push(pageContext.urlOriginal) - await router.isReady() - - let string = await renderToString(app) - if (firstError) { - throw firstError - } - - const payload = await renderSSRHead(head) - const vueQueryState = dehydrate(queryClient) - const piniaState = SuperJSON.stringify(pinia.state.value) - - const documentHtml = escapeInject` - - - ${dangerouslySkipEscape(payload.headTags)} - - - ${dangerouslySkipEscape(payload.bodyTagsOpen)} -
${dangerouslySkipEscape(string)}
- ${dangerouslySkipEscape(payload.bodyTags)} - - ` - - return { - documentHtml, - pageContext: { - vueQueryState, - piniaState, - }, - } -} diff --git a/web/renderer/_error.page.client.ts b/web/renderer/_error.page.client.ts new file mode 100644 index 00000000..b5cee809 --- /dev/null +++ b/web/renderer/_error.page.client.ts @@ -0,0 +1,9 @@ +import { createApp } from './error-app' +import type { PageContext } from './types' + +export { render } + +async function render(pageContext: PageContext) { + const params = createApp(pageContext) + params.app.mount('#app') +} diff --git a/web/pages/_error/+onRenderHtml.ts b/web/renderer/_error.page.server.ts similarity index 78% rename from web/pages/_error/+onRenderHtml.ts rename to web/renderer/_error.page.server.ts index c50e449f..c6b12c27 100644 --- a/web/pages/_error/+onRenderHtml.ts +++ b/web/renderer/_error.page.server.ts @@ -1,12 +1,19 @@ import { renderToString } from '@vue/server-renderer' import { dangerouslySkipEscape, escapeInject } from 'vike/server' import { createApp } from './error-app' -import type { PageContext } from '../../renderer/types' +import type { PageContext } from './types' import { renderSSRHead } from '@unhead/ssr' -export { onRenderHtml } +export { passToClient } +export { render } -async function onRenderHtml(pageContext: PageContext) { +const passToClient = [ + 'errorWhileRendering', + 'errorMessage', + 'statusCode', +] + +async function render(pageContext: PageContext) { const { app, head } = createApp(pageContext) const string = await renderToString(app) diff --git a/web/pages/_error/+Page.vue b/web/renderer/_error.page.vue similarity index 79% rename from web/pages/_error/+Page.vue rename to web/renderer/_error.page.vue index e3bde21c..ef58d080 100644 --- a/web/pages/_error/+Page.vue +++ b/web/renderer/_error.page.vue @@ -6,11 +6,11 @@