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

fix: iframe refresh on resize #531

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading