Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed form flickering bug #658

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions client/lib/forms/public-page.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let darkModeNodeParent = import.meta.client ? document.body : null
let darkModeNodeParent = import.meta.client ? document.documentElement : null

/**
* Handle form public pages dark mode and transparent mode
Expand All @@ -7,7 +7,7 @@ export function handleDarkMode (darkMode, elem = null) {
if (import.meta.server)
return

darkModeNodeParent = elem ?? document.body
darkModeNodeParent = elem ?? document.documentElement

// Dark mode
if (['dark', 'light'].includes(darkMode))
Expand Down Expand Up @@ -66,7 +66,7 @@ export function useClassWatcher (elem, className) {
export function useDarkMode (elem = ref(null)) {
// Define a computed property to handle the element reference reactively
const effectiveElem = computed(() => {
return elem.value || (process.client ? document.body : null)
return elem.value || (process.client ? document.documentElement : null)
})

// Pass the computed property to useClassWatcher
Expand All @@ -83,7 +83,7 @@ export function darkModeEnabled (elem = ref(null)) {

// Update isDark based on the current class
const updateIsDark = () => {
const finalElement = elem.value ?? document.body
const finalElement = elem.value ?? document.documentElement
isDark.value = finalElement.classList.contains('dark')
}

Expand Down Expand Up @@ -130,8 +130,8 @@ function handleDarkModeToggle (enabled) {
export function disableDarkMode () {
if (import.meta.server)
return
const body = document.body
body.classList.remove('dark')
const html = document.documentElement
html.classList.remove('dark')
// Remove event listener
window
.matchMedia('(prefers-color-scheme: dark)')
Expand Down
30 changes: 23 additions & 7 deletions client/pages/forms/[slug]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ const loadForm = async (setup=false) => {
formsStore.stopLoading()

// Adapt page to form: colors, custom code etc
handleDarkMode(form.value.dark_mode)
handleTransparentMode(form.value.transparent_background)
handleDarkMode(form.value?.dark_mode)
handleTransparentMode(form.value?.transparent_background)

// Remove 'hidden' class from html tag if present
nextTick(() => {
document.documentElement.classList.remove('hidden')
})
}

await loadForm(true)
Expand All @@ -154,6 +159,11 @@ onMounted(() => {
handleDarkMode(form.value?.dark_mode)
handleTransparentMode(form.value?.transparent_background)

// Remove 'hidden' class from html tag if present
nextTick(() => {
document.documentElement.classList.remove('hidden')
})

if (import.meta.client) {
if (form.value.custom_code) {
const scriptEl = document.createRange().createContextualFragment(form.value.custom_code)
Expand Down Expand Up @@ -237,9 +247,18 @@ useOpnSeoMeta({
}
})

const getHtmlClass = computed(() => {
return {
dark: form.value?.dark_mode === 'dark',
hidden: form.value?.dark_mode === 'auto' && import.meta.server,
}
})

useHead({
htmlAttrs: {
lang: (form.value?.language) ? form.value.language : 'en'
dir: () => form.value?.layout_rtl ? 'rtl' : 'ltr',
class: getHtmlClass.value,
lang: () => form.value?.language || 'en'
},
titleTemplate: (titleChunk) => {
if (pageMeta.value.page_title) {
Expand All @@ -259,9 +278,6 @@ useHead({
content: 'black-translucent'
},
] : {},
script: [{ src: '/widgets/iframeResizer.contentWindow.min.js' }],
htmlAttrs: () => ({
dir: form.value?.layout_rtl ? 'rtl' : 'ltr'
})
script: [{ src: '/widgets/iframeResizer.contentWindow.min.js' }]
})
</script>
Loading