Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
fix: iframe refresh on resize (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbo authored Nov 7, 2024
1 parent 42e7e5d commit 4cc6e9c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
35 changes: 30 additions & 5 deletions domains/grid/components/GridWidgetIframe.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
<script setup lang="ts">
import { useDebounceFn, useResizeObserver } from '@vueuse/core'
type Props = {
src: string
allow?: string
referrerpolicy?: IframeReferrerPolicy
allowfullscreen?: boolean
widget?: GridWidget
}
const props = defineProps<Props>()
const embedSrc = ref(props.src)
const iframeRef = ref<HTMLElement | null>(null)
const isLoaded = ref(false)
const handleLoad = () => {
isLoaded.value = true
}
const reloadIframe = () => {
embedSrc.value = ''
const onResize = useDebounceFn(() => {
embedSrc.value = props.src
}, 100)
onResize()
}
defineProps<Props>()
useResizeObserver(iframeRef, useDebounceFn(reloadIframe, 100))
</script>

<template>
<div class="h-full p-3">
<div ref="iframeRef" class="relative h-full p-3">
<AppLoader
v-if="!isLoaded"
class="absolute left-[calc(50%-20px)] top-[calc(50%-20px)]"
/>
<iframe
:src="src"
:src="embedSrc"
:allow="allow"
:referrerpolicy="referrerpolicy"
:allowfullscreen="allowfullscreen"
frameborder="0"
loading="lazy"
class="size-full overflow-hidden rounded-8"
></iframe>
@load="handleLoad"
>
</iframe>
</div>
</template>
2 changes: 1 addition & 1 deletion domains/grid/components/GridWidgetInstagram.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const processInstagramEmbeds = () => {
}
watch(
() => props,
() => props.src,
async () => {
embedSrc.value = ''
await nextTick()
Expand Down
2 changes: 1 addition & 1 deletion domains/grid/components/GridWidgetX.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const embedSrc = ref('')
// each change (add, edit) of the widget require to "reinstall" the twitter script
watch(
() => props,
() => props.src,
async () => {
embedSrc.value = ''
await nextTick()
Expand Down
1 change: 1 addition & 0 deletions domains/grid/schema/xWidgetSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ export const xWidgetBuilderSchema = xWidgetSchema
)

export type XWidgetProperties = z.input<typeof xWidgetSchema>
export type XType = z.infer<typeof xType>

0 comments on commit 4cc6e9c

Please sign in to comment.