Skip to content

Commit bf33d0a

Browse files
author
sqrtthree
committed
fix: Check container ref if exists to resolve error due to Sidebar component destruction
1 parent 1343fbd commit bf33d0a

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

components/Sidebar/index.vue

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export default {
161161
searchedOptions() {
162162
const results = []
163163
164-
this.sidebars.forEach(item => {
164+
this.sidebars.forEach((item) => {
165165
if (item.to) {
166166
results.push({
167167
to: item.to,
@@ -170,7 +170,7 @@ export default {
170170
}
171171
172172
if (item.headers) {
173-
item.headers.forEach(header => {
173+
item.headers.forEach((header) => {
174174
results.push({
175175
to: `${item.to}#${header.slug}`,
176176
text: header.title,
@@ -179,14 +179,14 @@ export default {
179179
}
180180
181181
if (item.children) {
182-
item.children.forEach(child => {
182+
item.children.forEach((child) => {
183183
results.push({
184184
to: child.to,
185185
text: child.title,
186186
})
187187
188188
if (child.headers) {
189-
child.headers.forEach(h => {
189+
child.headers.forEach((h) => {
190190
results.push({
191191
to: `${child.to}#${h.slug}`,
192192
text: h.title,
@@ -197,7 +197,7 @@ export default {
197197
}
198198
})
199199
200-
return results.filter(item =>
200+
return results.filter((item) =>
201201
(item.text || '')
202202
.toLowerCase()
203203
.includes(this.searchKeyword.toLowerCase())
@@ -218,7 +218,7 @@ export default {
218218
return decodeURIComponent(this.$route.fullPath)
219219
},
220220
localePathList() {
221-
return Object.keys(this.$site.locales || {}).map(locale => {
221+
return Object.keys(this.$site.locales || {}).map((locale) => {
222222
const item = this.$site.locales[locale]
223223
const languageTitle =
224224
config.get(this.$site, 'label', locale) || item.text || item.lang
@@ -230,7 +230,7 @@ export default {
230230
} else {
231231
path = this.$page.path.replace(this.$localePath, item.path) // Try to stay on the same page
232232
233-
const notFound = !this.$site.pages.some(page => page.path === path)
233+
const notFound = !this.$site.pages.some((page) => page.path === path)
234234
235235
if (notFound) {
236236
path = item.path // Fallback to homepage
@@ -251,7 +251,7 @@ export default {
251251
)
252252
253253
const order = groupOrderConfig
254-
? groupOrderConfig.filter(item => !!this.items[item])
254+
? groupOrderConfig.filter((item) => !!this.items[item])
255255
: Object.keys(this.items)
256256
257257
const index = order.indexOf('home')
@@ -267,10 +267,10 @@ export default {
267267
},
268268
sidebars() {
269269
return this.sidebarGroupOrder
270-
.map(item => {
270+
.map((item) => {
271271
return this.items[item]
272272
})
273-
.filter(item => item)
273+
.filter((item) => item)
274274
},
275275
},
276276
mounted() {
@@ -294,6 +294,10 @@ export default {
294294
this.containerWidth = width ? `${width}px` : '100%'
295295
},
296296
savePosition() {
297+
if (!this.$refs.container) {
298+
return
299+
}
300+
297301
const top = this.$refs.container.scrollTop
298302
299303
window.localStorage.setItem('vuepress_theme_api_sidebar_position', top)

0 commit comments

Comments
 (0)