perf(Editor): Don't reload iframe if already on chosen example content
@@ -12,12 +12,15 @@ export const getExample = (): string => {
export const setExample = (example: string): void => {
const url = new URL(window.location.href)
+ sessionStorage.setItem(keys.EXAMPLE, example)
+
+ if (url.searchParams.get(keys.EXAMPLE) !== example) {
url.searchParams.set(keys.EXAMPLE, example)
history.replaceState(null, 'none', url.toString())
- sessionStorage.setItem(keys.EXAMPLE, example)
+ }
const preview = getPreview()
- if (preview !== null) {
+ if (preview !== null && !preview.getAttribute('src')?.includes(example)) {
preview.setAttribute('src', `examples/${resolveExample(example)}.html`)
}
}
