perf(theme/search): prevent repeated rendering of same page (#2398)

pull/2429/head
烽宁 2 years ago committed by GitHub
parent 86a3c24d2a
commit e7be720ede
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -155,6 +155,9 @@ debouncedWatch(
if (canceled) return if (canceled) return
const c = new Map<string, Map<string, string>>() const c = new Map<string, Map<string, string>>()
for (const { id, mod } of mods) { for (const { id, mod } of mods) {
const mapId = id.slice(0, id.indexOf('#'))
let map = c.get(mapId)
if (map) continue
const comp = mod.default ?? mod const comp = mod.default ?? mod
if (comp?.render) { if (comp?.render) {
const app = createApp(comp) const app = createApp(comp)
@ -178,8 +181,6 @@ debouncedWatch(
const sections = div.innerHTML.split(headingRegex) const sections = div.innerHTML.split(headingRegex)
app.unmount() app.unmount()
sections.shift() sections.shift()
const mapId = id.slice(0, id.indexOf('#'))
let map = c.get(mapId)
if (!map) { if (!map) {
map = new Map() map = new Map()
c.set(mapId, map) c.set(mapId, map)

Loading…
Cancel
Save