Skip to content

Commit ccd79eb

Browse files
committed
chore: fix playground
1 parent 091fbc0 commit ccd79eb

File tree

3 files changed

+50
-38
lines changed

3 files changed

+50
-38
lines changed

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,9 @@ export default {
7676
name: "PlaygroundBlock",
7777
components: { PgEditor, RulesSettings, SnsBar },
7878
data() {
79-
const serializedString =
80-
(typeof window !== "undefined" && window.location.hash.slice(1)) ||
81-
""
82-
const state = deserializeState(serializedString)
8379
return {
84-
code: state.code || DEFAULT_CODE,
85-
rules: state.rules || Object.assign({}, DEFAULT_RULES_CONFIG),
80+
code: DEFAULT_CODE,
81+
rules: Object.assign({}, DEFAULT_RULES_CONFIG),
8682
messages: [],
8783
}
8884
},
@@ -103,19 +99,34 @@ export default {
10399
},
104100
watch: {
105101
serializedString(serializedString) {
106-
if (typeof window !== "undefined") {
102+
if (
103+
typeof window !== "undefined" &&
104+
serializedString !== window.location.hash.slice(1) &&
105+
!this._initializing
106+
) {
107107
window.location.replace(`#${serializedString}`)
108108
}
109109
},
110110
},
111111
mounted() {
112112
if (typeof window !== "undefined") {
113-
window.addEventListener("hashchange", this.onUrlHashChange)
113+
window.addEventListener("hashchange", this.processUrlHashChange)
114+
}
115+
const serializedString =
116+
(typeof window !== "undefined" && window.location.hash.slice(1)) ||
117+
""
118+
if (serializedString) {
119+
this._initializing = true
120+
this.rules = {}
121+
this.$nextTick().then(() => {
122+
this._initializing = false
123+
this.processUrlHashChange()
124+
})
114125
}
115126
},
116-
beforeDestroey() {
127+
beforeUnmount() {
117128
if (typeof window !== "undefined") {
118-
window.removeEventListener("hashchange", this.onUrlHashChange)
129+
window.removeEventListener("hashchange", this.processUrlHashChange)
119130
}
120131
},
121132
methods: {
@@ -125,7 +136,7 @@ export default {
125136
getRule(ruleId) {
126137
return getRule(ruleId)
127138
},
128-
onUrlHashChange() {
139+
processUrlHashChange() {
129140
const serializedString =
130141
(typeof window !== "undefined" &&
131142
window.location.hash.slice(1)) ||
@@ -135,8 +146,9 @@ export default {
135146
this.code = state.code || DEFAULT_CODE
136147
this.rules =
137148
state.rules || Object.assign({}, DEFAULT_RULES_CONFIG)
138-
this.script = state.script
149+
return true
139150
}
151+
return false
140152
},
141153
},
142154
}

package-lock.json

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"devDependencies": {
6363
"@changesets/cli": "^2.26.2",
6464
"@ota-meshi/eslint-plugin": "^0.15.1",
65-
"@ota-meshi/site-kit-eslint-editor-vue": "^0.1.0",
65+
"@ota-meshi/site-kit-eslint-editor-vue": "^0.1.2",
6666
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
6767
"@types/chai": "^4.2.22",
6868
"@types/eslint": "^8.44.0",

0 commit comments

Comments
 (0)