perf(nuxt): cache createClientOnly wrapper using weakmap (#7297)

This commit is contained in:
Julien Huang 2022-09-07 10:31:11 +02:00 committed by GitHub
parent 0a775e3f70
commit f8f5771646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,7 +18,13 @@ export default defineComponent({
} }
}) })
const cache = new WeakMap()
export function createClientOnly (component) { export function createClientOnly (component) {
if (cache.has(component)) {
return cache.get(component)
}
const clone = { ...component } const clone = { ...component }
if (clone.render) { if (clone.render) {
@ -53,5 +59,7 @@ export function createClientOnly (component) {
}) })
} }
cache.set(component, clone)
return clone return clone
} }