Skip to content

Commit

Permalink
fix: allow full usage of $img in plugins (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored May 19, 2021
1 parent 4ad029c commit b80f791
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/runtime/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ export function createImage (globalOptions: CreateImageOptions, nuxtContext: any
if (process.server) {
const { ssrContext } = ctx.nuxtContext
if (ssrContext) {
const ssrState = ssrContext.nuxt || { data: [] }
const ssrData = ssrState.data[0] || {}
const staticImages = ssrState._img = ssrData._img = ssrData._img || {}
const ssrState = ssrContext.nuxt || {}
const staticImages = ssrState._img = ssrState._img || {}
const mapToStatic: MapToStatic = ssrContext.image?.mapToStatic
if (typeof mapToStatic === 'function') {
const mappedURL = mapToStatic(image)
Expand Down
8 changes: 8 additions & 0 deletions src/runtime/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@ Vue.component('NPicture', NuxtPicture)

export default function (nuxtContext, inject) {
const $img = createImage(imageOptions, nuxtContext)

if (process.static && process.server) {
nuxtContext.beforeNuxtRender(({ nuxtState }) => {
const ssrData = nuxtState.data[0] || {}
ssrData._img = nuxtState._img || {}
})
}

inject('img', $img)
}

0 comments on commit b80f791

Please sign in to comment.