Skip to content

Commit

Permalink
fix: screen flashing during iframe navigation (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
sqcheah authored Dec 6, 2023
1 parent 2d8b525 commit de6f2ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
9 changes: 5 additions & 4 deletions components/PanelPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
const play = usePlaygroundStore()
const inputUrl = ref<string>('')
const inner = ref<{ iframe?: Ref<HTMLIFrameElement | undefined> }>()
const inner = ref<{ iframe?: HTMLIFrameElement | undefined }>()
// auto update inputUrl when location value changed
syncRef(computed(() => play.previewLocation.fullPath), inputUrl, { direction: 'ltr' })
function refreshIframe() {
if (play.previewUrl && inner.value?.iframe?.value) {
inner.value.iframe.value.src = play.previewUrl
if (play.previewUrl && inner.value?.iframe) {
play.updatePreviewUrl()
inner.value.iframe.src = play.previewUrl
inputUrl.value = play.previewLocation.fullPath
}
}
function navigate() {
play.previewLocation.fullPath = inputUrl.value
play.updatePreviewUrl()
const activeElement = document.activeElement
if (activeElement instanceof HTMLElement)
activeElement.blur()
Expand Down
4 changes: 4 additions & 0 deletions components/PanelPreviewClient.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ watch(
syncColorMode,
{ flush: 'sync' },
)
defineExpose({
iframe,
})
</script>

<template>
Expand Down
8 changes: 7 additions & 1 deletion stores/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export const usePlaygroundStore = defineStore('playground', () => {
origin: '',
fullPath: '',
})
const previewUrl = computed(() => previewLocation.value.origin + previewLocation.value.fullPath)
const previewUrl = ref('')

function updatePreviewUrl() {
previewUrl.value = previewLocation.value.origin + previewLocation.value.fullPath
}

const colorMode = useColorMode()

Expand Down Expand Up @@ -61,6 +65,7 @@ export const usePlaygroundStore = defineStore('playground', () => {
origin: url,
fullPath: '/',
}
updatePreviewUrl()
}
})

Expand Down Expand Up @@ -171,6 +176,7 @@ export const usePlaygroundStore = defineStore('playground', () => {
files,
webcontainer,
previewUrl,
updatePreviewUrl,
previewLocation,
restartServer: startServer,
downloadZip,
Expand Down

0 comments on commit de6f2ba

Please sign in to comment.