Beautiful Open-Source Form Builder
Refactor Crisp initialization and optimize third-party service loading
Julien Nahum62ebadcab4ef
diff --git a/client/app.vue b/client/app.vueindex 78b0c1349..712468c15 100644--- a/client/app.vue+++ b/client/app.vue@@ -9,7 +9,8 @@<NuxtPage /></NuxtLayout>- <ClientOnly>+ <!-- Third-party services and modals - only load when not on public form pages -->+ <ClientOnly v-if="!isPublicFormPage"><divclass="fixed z-[9999] left-0 bottom-0 p-4" id="admin-actions">@@ -17,9 +18,7 @@<ToolsStopImpersonation /></UButtonGroup></div>- </ClientOnly>- <ClientOnly><Clarity /><FeatureBase /><SubscriptionModal />@@ -34,6 +33,10 @@ import FeatureBase from "~/components/vendor/FeatureBase.vue"import Clarity from "~/components/vendor/Clarity.vue"const config = useRuntimeConfig()+const route = useRoute()++// Check if current page is a public form page (for performance optimization)+const isPublicFormPage = computed(() => route.name === 'forms-slug')// SEO and head configurationuseOpnSeoMeta({diff --git a/client/components/app/AppProvider.vue b/client/components/app/AppProvider.vueindex 8a037f671..5af5c4be4 100644--- a/client/components/app/AppProvider.vue+++ b/client/components/app/AppProvider.vue@@ -5,7 +5,6 @@</template><script setup>-import { computed, onMounted } from "vue"import { useAppStore } from "~/stores/app"const appStore = useAppStore()@@ -56,9 +55,4 @@ const tooltipConfig = {delayDuration: 100}-// Lifecycle-onMounted(() => {- useCrisp().onCrispInit()- useCrisp().showChat()-})</script>\ No newline at end of filediff --git a/client/plugins/crisp.client.js b/client/plugins/crisp.client.jsindex 327f9e4d7..a79b32120 100644--- a/client/plugins/crisp.client.js+++ b/client/plugins/crisp.client.js@@ -2,11 +2,46 @@ import { Crisp } from "crisp-sdk-web"export default defineNuxtPlugin(() => {const isIframe = useIsIframe()+ const router = useRouter()const crispWebsiteId = useRuntimeConfig().public.crispWebsiteId- const isPublicFormPage = useRoute().name === 'forms-slug'-- if (crispWebsiteId && !isIframe && !isPublicFormPage) {++ // Skip initialization in iframes or if no website ID+ if (isIframe || !crispWebsiteId) {+ return+ }++ const currentRoute = useRoute()+ const isPublicFormPage = () => currentRoute.name === 'forms-slug'++ // Initialize Crisp SDK and set up event listeners+ const initCrisp = () => {+ if (window.Crisp) return // Already initialized+Crisp.configure(crispWebsiteId)window.Crisp = Crisp++ // Set up Crisp callbacks (same as useCrisp().onCrispInit() + showChat())+ const appStore = useAppStore()+ Crisp.chat.onChatOpened(() => {+ appStore.crisp.chatOpened = true+ })+ Crisp.chat.onChatClosed(() => {+ appStore.crisp.chatOpened = false+ })+ Crisp.chat.show()+ appStore.crisp.hidden = false+ }++ // If not on public form page, initialize immediately+ if (!isPublicFormPage()) {+ initCrisp()+ } else {+ // Lazy init: wait for navigation away from public form page+ const unwatch = router.afterEach((to) => {+ if (to.name !== 'forms-slug') {+ initCrisp()+ unwatch() // Stop watching after initialization+ }+ })}})diff --git a/client/sentry.client.config.ts b/client/sentry.client.config.tsindex a5a154b32..ab0bb7254 100644--- a/client/sentry.client.config.ts+++ b/client/sentry.client.config.ts@@ -5,16 +5,8 @@ Sentry.init({// dsn: useRuntimeConfig().public.sentry.dsn,dsn: useRuntimeConfig().public.SENTRY_DSN_PUBLIC ?? null,- // This sets the sample rate to be 10%. You may want this to be 100% while- // in development and sample at a lower rate in production- replaysSessionSampleRate: 0.1,-- // If the entire session is not sampled, use the below sample rate to sample- // sessions when an error occurs.- replaysOnErrorSampleRate: 1.0,-// If you don't want to use Session Replay, just remove the line below:- integrations: [Sentry.replayIntegration()],+ integrations: [],// Setting this option to true will print useful information to the console while you're setting up Sentry.debug: false,