diff --git a/docs/.vitepress/theme/components/playground-block.vue b/docs/.vitepress/theme/components/playground-block.vue index 549cc8d..aef7e96 100644 --- a/docs/.vitepress/theme/components/playground-block.vue +++ b/docs/.vitepress/theme/components/playground-block.vue @@ -89,12 +89,9 @@ export default { name: "PlaygroundBlock", components: { PgEditor, RulesSettings, SnsBar }, data() { - const serializedString = - (typeof window !== "undefined" && window.location.hash.slice(1)) || ""; - const state = deserializeState(serializedString); return { - code: state.code || DEFAULT_CODE, - rules: state.rules || Object.assign({}, DEFAULT_RULES_CONFIG), + code: DEFAULT_CODE, + rules: Object.assign({}, DEFAULT_RULES_CONFIG), messages: [], }; }, @@ -115,12 +112,16 @@ export default { }, watch: { serializedString(serializedString) { - if (typeof window !== "undefined") { + if ( + typeof window !== "undefined" && + serializedString !== window.location.hash.slice(1) + ) { window.location.replace(`#${serializedString}`); } }, }, mounted() { + this.onUrlHashChange(); if (typeof window !== "undefined") { window.addEventListener("hashchange", this.onUrlHashChange); } @@ -144,7 +145,6 @@ export default { const state = deserializeState(serializedString); this.code = state.code || DEFAULT_CODE; this.rules = state.rules || Object.assign({}, DEFAULT_RULES_CONFIG); - this.script = state.script; } }, },