Expose nuxtImage:updateImageMap event globally
- Target: static
- Current behaviour:
staticImageMapis updated onlyafterEachrouter changes.
Expose nuxtImage:updateImageMap event globally to be able to force nuxt/image to append _pagePayload?.data?.[0]?._img from any other generated payload without any Route change or on beforeRouteUpdate.
beforeRouteUpdate(to: Route, from: Route, next: Function) {
if (this.$store.state.isAFancyEmbeddedPage) {
/* new data, new components requiring some nuxt-img or nuxt-picture */
this.pageData = this.$store.state.fancyEmbeddedPageData
// Need to emit an event to force NuxtImage to append new pagePayload._img
// to current page staticImageMap
this.$nuxt.$emit('nuxtImage:updateImageMap')
} else {
next()
}
}
Hi @ambroisemaupate thanks for PR. Would you please create a reproduction for current issue? So we can discover possible solutions for this.
Hi @pi0
Here is a reproduction of the use case https://github.com/manuelodelain/nuxt-image-update-image-map
The scenario is: we have to open a page into a modal, but keep the ability to have this same page as a regular page (ie with a proper url).
The idea is to keep the lifecycle of a regular page (fetch the data with asyncData()), and if the page has to be opened as a modal the router is stopped, we keep the data from the asyncData(), inject it into a modal component and we handle manually the url with the History API.
- target: static
- Expected behavior: After the generation, the images should be served from the
dist/folder - Current behavior: After the generation, if the router is interrupted, the images use the original src attribute.
The issue here is that Nuxt Image updates the static image map using the afterEach() guard.
This PR exposes a global event to manually update the static image map if needed.
Hi @pi0
Have you any feedback on this PR?
Thanks
Hi @ambroisemaupate. Can you still reproduce it on ^0.4.14?
Hi @ambroisemaupate. Can you still reproduce it on ^0.4.14?
Yes, I think your testing repo is still relevant @manuelodelain