From 7cb3a2dbebc3420512092a871cd8daa55b64fc60 Mon Sep 17 00:00:00 2001 From: Tony Air Date: Sun, 23 Jun 2024 01:37:22 +0200 Subject: [PATCH] IMPR: lower CLS --- app/client/src/js/_graphql.js | 47 +++++++++++++----------- app/templates/Includes/LoadingSpinner.ss | 10 ++++- babel.config.json | 6 ++- package.json | 2 +- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/app/client/src/js/_graphql.js b/app/client/src/js/_graphql.js index 9f5cc21..cfc0859 100644 --- a/app/client/src/js/_graphql.js +++ b/app/client/src/js/_graphql.js @@ -4,26 +4,31 @@ import Events from '@a2nt/ss-bootstrap-ui-webpack-boilerplate-react/src/js/_even const m = require("mithril") // eslint-disable-line window.addEventListener('prefetch-loaded', () => { - const MainContentContainer = document.getElementById('MainContent') - - const MainContent = document.createElement('div') - if (!MainContentContainer.dataset['legacy']) { - MainContent.classList.add('page--container') - MainContentContainer.append(MainContent) - - const page = require('@a2nt/mithril-ui/src/js/ui/page/tpl') - m.mount(MainContent, page) - } else { - // legacy fallback - const spinner = document.getElementById('PageLoading') - if (spinner) { - window.addEventListener(`${Events.LOADED}`, () => { - spinner.classList.add('d-none') - }) - - window.addEventListener(`${Events.AJAX}`, () => { - spinner.classList.add('d-none') - }) + if (window.initAjaxOnce) { + return } - } + + const MainContentContainer = document.getElementById('MainContent') + + const MainContent = document.createElement('div') + if (!MainContentContainer.dataset['legacy']) { + MainContent.classList.add('page--container') + MainContentContainer.append(MainContent) + + const page = require('@a2nt/mithril-ui/src/js/ui/page/tpl') + m.mount(MainContent, page) + } else { + // legacy fallback + const spinner = document.getElementById('PageLoading') + if (spinner) { + window.addEventListener(`${Events.LOADED}`, () => { + spinner.classList.add('d-none') + }) + + window.addEventListener(`${Events.AJAX}`, () => { + spinner.classList.add('d-none') + }) + } + } + window.initAjaxOnce = true }) diff --git a/app/templates/Includes/LoadingSpinner.ss b/app/templates/Includes/LoadingSpinner.ss index e5fdb52..528218c 100644 --- a/app/templates/Includes/LoadingSpinner.ss +++ b/app/templates/Includes/LoadingSpinner.ss @@ -1,15 +1,23 @@