Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Update Nuxt template overrides to latest versions of templates (#3305)

sarayourfriendd64c89da7582
diff --git a/frontend/nuxt-template-overrides/App.js b/frontend/nuxt-template-overrides/App.js
index 590201b49..132c5fbc1 100644
--- a/frontend/nuxt-template-overrides/App.js
+++ b/frontend/nuxt-template-overrides/App.js
@@ -12,15 +12,14 @@ import { decode, parsePath, withoutBase, withoutTrailingSlash, normalizeURL } fr
'sanitizeComponent'
]: []
] %>
+<% if (utilsImports.length) { %>import { <%= utilsImports.join(', ') %> } from './utils'<% } %>
<% css.forEach((c) => { %>
import '<%= relativeToBuild(resolvePath(c.src || c, { isStyle: true })) %>'
<% }) %>
-<% if (utilsImports.length) { %>import { <%= utilsImports.join(', ') %> } from './utils'<% } %>
import NuxtError from '<%= components.ErrorPage ? components.ErrorPage : "./components/nuxt-error.vue" %>'
<% if (loading) { %>import NuxtLoading from '<%= (typeof loading === "string" ? loading : "./components/nuxt-loading.vue") %>'<% } %>
<% if (buildIndicator) { %>import NuxtBuildIndicator from './components/nuxt-build-indicator'<% } %>
-
<% if (features.layouts) { %>
<%= Object.keys(layouts).map((key) => {
if (splitChunks.layouts) {
@@ -175,23 +174,16 @@ export default {
}
<% if (loading) { %>this.$loading.start()<% } %>
- const promises = pages.map((page) => {
- const p = []
+ const promises = pages.map(async (page) => {
+ let p = []
<% if (features.fetch) { %>
// Old fetch
if (page.$options.fetch && page.$options.fetch.length) {
p.push(promisify(page.$options.fetch, this.context))
}
- if (page.$fetch) {
- p.push(page.$fetch())
- } else {
- // Get all component instance to call $fetch
- for (const component of getChildrenComponentInstancesUsingFetch(page.$vnode.componentInstance)) {
- p.push(component.$fetch())
- }
- }
<% } %>
+
<% if (features.asyncData) { %>
if (page.$options.asyncData) {
p.push(
@@ -204,6 +196,22 @@ export default {
)
}
<% } %>
+
+ <% if (features.fetch) { %>
+ // Wait for asyncData & old fetch to finish
+ await Promise.all(p)
+ // Cleanup refs
+ p = []
+
+ if (page.$fetch) {
+ p.push(page.$fetch())
+ }
+ // Get all component instance to call $fetch
+ for (const component of getChildrenComponentInstancesUsingFetch(page.$vnode.componentInstance)) {
+ p.push(component.$fetch())
+ }
+ <% } %>
+
return Promise.all(p)
})
try {
diff --git a/frontend/nuxt-template-overrides/index.js b/frontend/nuxt-template-overrides/index.js
index 7b33c9859..088509c72 100644
--- a/frontend/nuxt-template-overrides/index.js
+++ b/frontend/nuxt-template-overrides/index.js
@@ -46,7 +46,7 @@ Vue.component(Nuxt.name, Nuxt)
Object.defineProperty(Vue.prototype, '<%= globals.nuxt %>', {
get() {
- const globalNuxt = this.$root.$options.<%= globals.nuxt %>
+ const globalNuxt = this.$root ? this.$root.$options.<%= globals.nuxt %> : null
if (process.client && !globalNuxt && typeof window !== 'undefined') {
return window.<%= globals.nuxt %>
}
@@ -92,10 +92,10 @@ function registerModule (path, rawModule, options = {}) {
<% } %>
async function createApp(ssrContext, config = {}) {
- const router = await createRouter(ssrContext, config)
+ const store = <%= store ? 'createStore(ssrContext)' : 'null' %>
+ const router = await createRouter(ssrContext, config, { store })
<% if (store) { %>
- const store = createStore(ssrContext)
// Add this.$router into store actions/mutations
store.$router = router
<% if (mode === 'universal') { %>
@@ -183,6 +183,7 @@ async function createApp(ssrContext, config = {}) {
req: ssrContext ? ssrContext.req : undefined,
res: ssrContext ? ssrContext.res : undefined,
beforeRenderFns: ssrContext ? ssrContext.beforeRenderFns : undefined,
+ beforeSerializeFns: ssrContext ? ssrContext.beforeSerializeFns : undefined,
ssrContext
})