Skip to content

Commit e97259d

Browse files
committed
chore: fix playground
1 parent 2d265ea commit e97259d

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

docs/.vitepress/theme/components/playground-block.vue

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,31 @@ export default {
7474
serializedString(serializedString) {
7575
if (
7676
typeof window !== "undefined" &&
77-
serializedString !== window.location.hash.slice(1)
77+
serializedString !== window.location.hash.slice(1) &&
78+
!this._initializing
7879
) {
7980
window.location.replace(`#${serializedString}`);
8081
}
8182
},
8283
},
8384
mounted() {
84-
this.onUrlHashChange();
8585
if (typeof window !== "undefined") {
86-
window.addEventListener("hashchange", this.onUrlHashChange);
86+
window.addEventListener("hashchange", this.processUrlHashChange);
87+
}
88+
const serializedString =
89+
(typeof window !== "undefined" && window.location.hash.slice(1)) || "";
90+
if (serializedString) {
91+
this._initializing = true;
92+
this.rules = {};
93+
this.$nextTick().then(() => {
94+
this._initializing = false;
95+
this.processUrlHashChange();
96+
});
8797
}
8898
},
89-
beforeDestroey() {
99+
beforeUnmount() {
90100
if (typeof window !== "undefined") {
91-
window.removeEventListener("hashchange", this.onUrlHashChange);
101+
window.removeEventListener("hashchange", this.processUrlHashChange);
92102
}
93103
},
94104
methods: {
@@ -98,14 +108,16 @@ export default {
98108
getRule(ruleId) {
99109
return getRule(ruleId);
100110
},
101-
onUrlHashChange() {
111+
processUrlHashChange() {
102112
const serializedString =
103113
(typeof window !== "undefined" && window.location.hash.slice(1)) || "";
104114
if (serializedString !== this.serializedString) {
105115
const state = deserializeState(serializedString);
106116
this.code = state.code || DEFAULT_CODE;
107117
this.rules = state.rules || Object.assign({}, DEFAULT_RULES_CONFIG);
118+
return true;
108119
}
120+
return false;
109121
},
110122
},
111123
};

0 commit comments

Comments
 (0)