From 1cc143ef275d1f2f38fed1f71237361ff8dbb646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Mon, 5 Aug 2024 15:35:08 +0200 Subject: [PATCH] fix: various issues to reduce effect_update_depth_exceeded + use `scroll` from Motion One for parallax --- .../components/atoms/ScrollingTitle.svelte | 2 +- .../molecules/Location/Location.svelte | 2 +- .../molecules/Switcher/Switcher.svelte | 2 +- .../InteractiveGlobe/InteractiveGlobe.svelte | 4 +- .../organisms/ShopBanner/ShopBanner.svelte | 4 +- .../(site)/[country]/[location]/+page.svelte | 61 +++++++++---------- .../src/routes/(site)/about/+page.svelte | 23 ++++--- apps/website/src/style/pages/_about.scss | 2 +- apps/website/src/style/pages/_location.scss | 4 +- 9 files changed, 50 insertions(+), 54 deletions(-) diff --git a/apps/website/src/components/atoms/ScrollingTitle.svelte b/apps/website/src/components/atoms/ScrollingTitle.svelte index 31a5cf1..96668d2 100644 --- a/apps/website/src/components/atoms/ScrollingTitle.svelte +++ b/apps/website/src/components/atoms/ScrollingTitle.svelte @@ -35,7 +35,7 @@ let scrollY = $state() let innerWidth = $state() let innerHeight = $state() - let titleEl = $state() + let titleEl: HTMLElement // Check if title is larger than viewport to translate it const isLarger = $derived(titleEl && titleEl.offsetWidth >= innerWidth) diff --git a/apps/website/src/components/molecules/Location/Location.svelte b/apps/website/src/components/molecules/Location/Location.svelte index 0d994a3..d278b87 100644 --- a/apps/website/src/components/molecules/Location/Location.svelte +++ b/apps/website/src/components/molecules/Location/Location.svelte @@ -24,7 +24,7 @@ const { settings }: any = getContext('global') - let locationEl = $state() + let locationEl: HTMLElement let photoIndex = $state(0) // Location date limit diff --git a/apps/website/src/components/molecules/Switcher/Switcher.svelte b/apps/website/src/components/molecules/Switcher/Switcher.svelte index b361348..f617675 100644 --- a/apps/website/src/components/molecules/Switcher/Switcher.svelte +++ b/apps/website/src/components/molecules/Switcher/Switcher.svelte @@ -12,7 +12,7 @@ const { settings: { switcher_links } }: any = getContext('global') - let switcherEl = $state() + let switcherEl: HTMLElement let isOpen = $state(false) diff --git a/apps/website/src/components/organisms/InteractiveGlobe/InteractiveGlobe.svelte b/apps/website/src/components/organisms/InteractiveGlobe/InteractiveGlobe.svelte index 6414965..d3a40a6 100644 --- a/apps/website/src/components/organisms/InteractiveGlobe/InteractiveGlobe.svelte +++ b/apps/website/src/components/organisms/InteractiveGlobe/InteractiveGlobe.svelte @@ -33,8 +33,8 @@ } = $props() let innerWidth = $state() - let globeParentEl = $state() - let globeEl = $state() + let globeParentEl: HTMLElement + let globeEl: HTMLElement let globe = $state() let observer: IntersectionObserver let animation = $state() diff --git a/apps/website/src/components/organisms/ShopBanner/ShopBanner.svelte b/apps/website/src/components/organisms/ShopBanner/ShopBanner.svelte index 0cc1625..50a470b 100644 --- a/apps/website/src/components/organisms/ShopBanner/ShopBanner.svelte +++ b/apps/website/src/components/organisms/ShopBanner/ShopBanner.svelte @@ -21,8 +21,8 @@ let innerWidth = $state() let navObserver: IntersectionObserver - let introEl = $state() - let navChooseEl = $state() + let introEl: HTMLElement + let navChooseEl: HTMLElement let scrolledPastIntro = $state(false) diff --git a/apps/website/src/routes/(site)/[country]/[location]/+page.svelte b/apps/website/src/routes/(site)/[country]/[location]/+page.svelte index ce133e2..ff019bf 100644 --- a/apps/website/src/routes/(site)/[country]/[location]/+page.svelte +++ b/apps/website/src/routes/(site)/[country]/[location]/+page.svelte @@ -5,7 +5,7 @@ - - -
+

Houses @@ -269,7 +266,7 @@ {#if location?.hero?.id} - + () let innerWidth = $state() - let innerHeight = $state() - let photosGridEl = $state() - let photosGridOffset = $state() + let photosGridEl: HTMLElement + let photosGridParallax = $state() let currentStep = $state(0) let emailCopied = $state() let emailCopiedTimeout: ReturnType | number - const parallaxPhotos = $derived(photosGridEl && map(scrollY, photosGridOffset - innerHeight, photosGridOffset + innerHeight / 1.5, 0, innerHeight * 0.15, true)) const fadedPhotosIndexes = $derived( innerWidth > 768 ? [0, 2, 5, 7, 9, 12, 17, 20, 22, 26, 30, 32, 34] @@ -41,9 +38,11 @@ $effect(() => { - // Update photos grid top offset - photosGridOffset = photosGridEl.offsetTop - + // Add parallax to photos grid + scroll(({ y }) => photosGridParallax = lerp(-15, 10, y.progress), { + target: photosGridEl, + offset: ['start end', 'end start'] + }) /** * Animations @@ -171,7 +170,7 @@ }) - +
-
+
{#each data.photos as { image: { id }, title }, index}