Skip to content

Commit 4ff1fe6

Browse files
committed
fix: resolve some issues pointed out by coderabbit
1 parent a9b656a commit 4ff1fe6

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

app/pages/package/[[org]]/[name].vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ const isHydratingWithServerContent = shallowRef(
271271
// HTML as a static snapshot while data refetches, avoiding any visual flash.
272272
const serverRenderedHtml = shallowRef<string | null>(
273273
isHydratingWithServerContent.value
274-
? (document.querySelector('article')?.innerHTML ?? null)
274+
? (document.getElementById('package-article')?.innerHTML ?? null)
275275
: null,
276276
)
277277
@@ -739,14 +739,21 @@ const showSkeleton = shallowRef(false)
739739
/>
740740

741741
<!-- During hydration without payload, show captured server HTML as a static snapshot.
742-
This avoids a visual flash: the user sees the server content while data refetches. -->
742+
This avoids a visual flash: the user sees the server content while data refetches.
743+
v-html is safe here: the content originates from the server's own SSR output,
744+
captured from the DOM before hydration — it is not user-controlled input. -->
743745
<article
744746
v-else-if="isHydratingWithServerContent && serverRenderedHtml"
747+
id="package-article"
745748
:class="$style.packagePage"
746749
v-html="serverRenderedHtml"
747750
/>
748751

749-
<article v-else-if="status === 'success' && pkg" :class="$style.packagePage">
752+
<article
753+
v-else-if="status === 'success' && pkg"
754+
id="package-article"
755+
:class="$style.packagePage"
756+
>
750757
<!-- Package header -->
751758
<header
752759
class="sticky top-14 z-1 bg-[--bg] py-2 border-border"

server/plugins/payload-cache.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ export default defineNitroPlugin(nitroApp => {
119119

120120
if (isPayloadRequest) {
121121
// This was a _payload.json render — cache the response body directly
122+
if (typeof response.body !== 'string') return
122123
const routePath = getRouteFromPayloadUrl(ctx.event.path)
123124
cachePayload(ctx.event, routePath, {
124-
body: response.body as string,
125+
body: response.body,
125126
statusCode: response.statusCode ?? 200,
126127
headers: {
127128
'content-type': 'application/json;charset=utf-8',
@@ -133,7 +134,8 @@ export default defineNitroPlugin(nitroApp => {
133134
// stashed a serialized payload on the event context
134135
const cachedPayload = ctx.event.context._cachedPayloadResponse
135136
if (cachedPayload) {
136-
const routePath = ctx.event.path === '/' ? '/' : ctx.event.path.replace(/\/$/, '')
137+
const pathWithoutQuery = ctx.event.path.replace(/\?.*$/, '')
138+
const routePath = pathWithoutQuery === '/' ? '/' : pathWithoutQuery.replace(/\/$/, '')
137139
cachePayload(ctx.event, routePath, cachedPayload)
138140
// Clean up the stashed payload
139141
delete ctx.event.context._cachedPayloadResponse

0 commit comments

Comments
 (0)