Skip to content

Commit

Permalink
fix: add guard for ssrContext existence
Browse files Browse the repository at this point in the history
ref: #258, #249
  • Loading branch information
pi0 committed May 12, 2021
1 parent 9a93f19 commit d8aa3a1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/runtime/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ export function createImage (globalOptions: CreateImageOptions, nuxtContext: any

if (process.server) {
const { ssrContext } = ctx.nuxtContext
const ssrState = ssrContext.nuxt
const ssrData = ssrContext.nuxt.data[0]
const staticImages = ssrState._img = ssrData._img = ssrData._img || {}
const mapToStatic: MapToStatic = ssrContext.image?.mapToStatic
if (typeof mapToStatic === 'function') {
const mappedURL = mapToStatic(image)
if (mappedURL) {
staticImages[image.url] = mappedURL
image.url = mappedURL
if (ssrContext) {
const ssrState = ssrContext.nuxt || { data: [] }
const ssrData = ssrState.data[0] || {}
const staticImages = ssrState._img = ssrData._img = ssrData._img || {}
const mapToStatic: MapToStatic = ssrContext.image?.mapToStatic
if (typeof mapToStatic === 'function') {
const mappedURL = mapToStatic(image)
if (mappedURL) {
staticImages[image.url] = mappedURL
image.url = mappedURL
}
}
}
}
Expand Down

0 comments on commit d8aa3a1

Please sign in to comment.