diff --git a/docs/assets/scripts/preset-theme-picker.js b/docs/assets/scripts/preset-theme-picker.js index 5a4c6e377..9965d8c37 100644 --- a/docs/assets/scripts/preset-theme-picker.js +++ b/docs/assets/scripts/preset-theme-picker.js @@ -47,22 +47,6 @@ const presetTheme = new ThemeAspect({ }, }); -/** - * Without this, there's a flash of the incorrect preset theme. - */ -function updateSelectionBeforeTurboLoad(e) { - const newElement = e.detail.newBody || e.detail.newFrame || e.detail.newStream; - if (newElement) { - presetTheme.syncUI(newElement); - } -} - -['turbo:before-render', 'turbo:before-stream-render', 'turbo:before-frame-render'].forEach(eventName => { - document.addEventListener(eventName, updateSelectionBeforeTurboLoad); -}); - window.addEventListener('turbo:render', e => { presetTheme.applyChange({ behavior: 'instant' }); }); - -window.presetTheme = presetTheme; diff --git a/docs/assets/scripts/theme-picker.js b/docs/assets/scripts/theme-picker.js index 1679d9ac0..b1f31f76b 100644 --- a/docs/assets/scripts/theme-picker.js +++ b/docs/assets/scripts/theme-picker.js @@ -34,6 +34,15 @@ export class ThemeAspect { this.set(picker.value); } }); + + ['turbo:before-render', 'turbo:before-stream-render', 'turbo:before-frame-render'].forEach(eventName => { + document.addEventListener(eventName, e => { + const newElement = e.detail.newBody || e.detail.newFrame || e.detail.newStream; + if (newElement) { + this.syncUI(newElement); + } + }); + }); } get() {