Skip to content

Commit

Permalink
web: Migrate to vike v1 paths
Browse files Browse the repository at this point in the history
  • Loading branch information
schneefux committed Dec 6, 2023
1 parent 55d4f8f commit cacf7d2
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 87 deletions.
4 changes: 2 additions & 2 deletions web/renderer/_error.page.vue → web/pages/_error/+Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<script lang="ts">
import { defineComponent } from 'vue'
import ErrorLayout from '~/layouts/error.vue'
import ErrorLayout from '../../layouts/error.vue'
import '~/assets/css/tailwind.css'
import '~/assets/css/transitions.css'
import '~/assets/css/fonts.css'
import Error from '../pages/error.vue'
import Error from '../error.vue'
export default defineComponent({
components: {
Expand Down
7 changes: 7 additions & 0 deletions web/pages/_error/+config.h.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
passToClient: [
'errorWhileRendering',
'errorMessage',
'statusCode',
],
}
9 changes: 9 additions & 0 deletions web/pages/_error/+onRenderClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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')
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import { renderToString } from '@vue/server-renderer'
import { dangerouslySkipEscape, escapeInject } from 'vike/server'
import { createApp } from './error-app'
import type { PageContext } from './types'
import type { PageContext } from '../../renderer/types'
import { renderSSRHead } from '@unhead/ssr'

export { passToClient }
export { render }
export { onRenderHtml }

const passToClient = [
'errorWhileRendering',
'errorMessage',
'statusCode',
]

async function render(pageContext: PageContext) {
async function onRenderHtml(pageContext: PageContext) {
const { app, head } = createApp(pageContext)

const string = await renderToString(app)
Expand Down
4 changes: 2 additions & 2 deletions web/renderer/error-app.ts → web/pages/_error/error-app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSSRApp } from 'vue'
import type { PageContext } from './types'
import { setPageContext } from './usePageContext'
import type { PageContext } from '../../renderer/types'
import { setPageContext } from '../../renderer/usePageContext'
import { createHead } from '@unhead/vue'
import { ClientOnly } from '@schneefux/klicker/components'

Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions web/renderer/+config.h.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default {
passToClient: [
'vueQueryState',
'piniaState',
'errorWhileRendering',
'envConfig',
'validated',
'statusCode',
'redirectTo',
'refs',
'localeMessages',
],
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
import { renderToString } from '@vue/server-renderer'
import { dangerouslySkipEscape, escapeInject } from 'vike/server'
import { createApp } from './app'
import type { Config, PageContext } from './types'
import type { PageContextBuiltInServer } from 'vike/types'
import { dehydrate } from '@tanstack/vue-query'
import { renderSSRHead } from '@unhead/ssr'
import SuperJSON from 'superjson'
import Sentry from '@sentry/vue'
import { getTraduoraToken, TraduoraToken } from '@/locales'

export { onBeforeRender }
export { passToClient }
export { render }

const passToClient = [
'vueQueryState',
'piniaState',
'errorWhileRendering',
'envConfig',
'validated',
'statusCode',
'redirectTo',
'refs',
'localeMessages',
]

let cachedTraduoraToken: TraduoraToken | undefined = undefined
async function onBeforeRender(pageContext: PageContext) {
Expand Down Expand Up @@ -73,44 +52,3 @@ async function onBeforeRender(pageContext: PageContext) {
}
}
}

async function render(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`<!DOCTYPE html>
<html${dangerouslySkipEscape(payload.htmlAttrs)}>
<head>
${dangerouslySkipEscape(payload.headTags)}
</head>
<body${dangerouslySkipEscape(payload.bodyAttrs)}>
${dangerouslySkipEscape(payload.bodyTagsOpen)}
<div id="app">${dangerouslySkipEscape(string)}</div>
${dangerouslySkipEscape(payload.bodyTags)}
</body>
</html>`

return {
documentHtml,
pageContext: {
vueQueryState,
piniaState,
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
RewriteFrames as RewriteFramesIntegration,
} from '@sentry/integrations'

export { render }
export { onRenderClient }

async function render(pageContext: PageContext) {
async function onRenderClient(pageContext: PageContext) {
const params = createApp(pageContext)

Sentry.init({
Expand Down
51 changes: 51 additions & 0 deletions web/renderer/+onRenderHtml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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`<!DOCTYPE html>
<html${dangerouslySkipEscape(payload.htmlAttrs)}>
<head>
${dangerouslySkipEscape(payload.headTags)}
</head>
<body${dangerouslySkipEscape(payload.bodyAttrs)}>
${dangerouslySkipEscape(payload.bodyTagsOpen)}
<div id="app">${dangerouslySkipEscape(string)}</div>
${dangerouslySkipEscape(payload.bodyTags)}
</body>
</html>`

return {
documentHtml,
pageContext: {
vueQueryState,
piniaState,
},
}
}
File renamed without changes.
9 changes: 0 additions & 9 deletions web/renderer/_error.page.client.ts

This file was deleted.

0 comments on commit cacf7d2

Please sign in to comment.