From 4e7406a98edfef43347ad19917e80d99ae689c66 Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Wed, 22 Jan 2025 14:31:01 +0100 Subject: [PATCH 01/13] Fix layout shift on thumbnails & quantity --- resources/views/components/quantity.blade.php | 2 + .../product/partials/gallery/popup.blade.php | 4 +- .../product/partials/gallery/slider.blade.php | 27 +++-- .../partials/gallery/thumbnails.blade.php | 104 +++++++++++------- .../views/product/partials/images.blade.php | 19 +--- 5 files changed, 90 insertions(+), 66 deletions(-) diff --git a/resources/views/components/quantity.blade.php b/resources/views/components/quantity.blade.php index 940abf093..689229add 100644 --- a/resources/views/components/quantity.blade.php +++ b/resources/views/components/quantity.blade.php @@ -6,6 +6,7 @@
-
\ No newline at end of file + diff --git a/resources/views/product/partials/gallery/slider.blade.php b/resources/views/product/partials/gallery/slider.blade.php index 029ac8967..82835de99 100644 --- a/resources/views/product/partials/gallery/slider.blade.php +++ b/resources/views/product/partials/gallery/slider.blade.php @@ -1,23 +1,28 @@
{{ $product->name }} - - + + @if (count($product->images ?? []) > 1) + + + @endif
- + diff --git a/resources/views/product/partials/gallery/thumbnails.blade.php b/resources/views/product/partials/gallery/thumbnails.blade.php index de5cd213e..aacdc7207 100644 --- a/resources/views/product/partials/gallery/thumbnails.blade.php +++ b/resources/views/product/partials/gallery/thumbnails.blade.php @@ -1,40 +1,70 @@ -@php($breakpoints = ['xl' => 7, 'lg' => 5, 'md' => 4, 'sm' => 3, 'xs' => 4]) -
- + images)) + src="/storage/{{ config('rapidez.store') }}/resizes/80x80/magento/catalog/product/{{ $product->images[$imageId] }}.webp" + @endif + v-bind:src="'/storage/{{ config('rapidez.store') }}/resizes/80x80/magento/catalog/product/' + images[{{ $imageId }}] + '.webp'" + alt="{{ $product->name }}" + class="block max-h-full w-auto object-contain" + width="80" + height="80" + /> + +
images) - $imageId - 1) v-cloak @endunless + v-if="images.length - {{ $imageId }} - 1" + > + +
+ + @endfor
diff --git a/resources/views/product/partials/images.blade.php b/resources/views/product/partials/images.blade.php index a8e9c54b7..b83e44148 100644 --- a/resources/views/product/partials/images.blade.php +++ b/resources/views/product/partials/images.blade.php @@ -4,28 +4,15 @@ @include('rapidez::wishlist.button') @endif - @if (count($product->images)) -
-
- {{ $product->name }} -
-
- @endif - +
@include('rapidez::product.partials.gallery.slider') - @include('rapidez::product.partials.gallery.thumbnails') + @includeWhen(count($product->images) > 1, 'rapidez::product.partials.gallery.thumbnails')
@include('rapidez::product.partials.gallery.popup')
- \ No newline at end of file + From 105b802341bf2016ceab6c0ea44bcedac07375f6 Mon Sep 17 00:00:00 2001 From: Jade-GG Date: Wed, 22 Jan 2025 13:31:26 +0000 Subject: [PATCH 02/13] Apply fixes from Duster --- resources/views/product/partials/gallery/thumbnails.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/product/partials/gallery/thumbnails.blade.php b/resources/views/product/partials/gallery/thumbnails.blade.php index aacdc7207..bae0296fa 100644 --- a/resources/views/product/partials/gallery/thumbnails.blade.php +++ b/resources/views/product/partials/gallery/thumbnails.blade.php @@ -32,7 +32,7 @@ > images)) + @if ($imageId < count($product->images)) src="/storage/{{ config('rapidez.store') }}/resizes/80x80/magento/catalog/product/{{ $product->images[$imageId] }}.webp" @endif v-bind:src="'/storage/{{ config('rapidez.store') }}/resizes/80x80/magento/catalog/product/' + images[{{ $imageId }}] + '.webp'" From 0033dd720495574b5961de42afa3a60bd26fa4d4 Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Wed, 22 Jan 2025 14:41:58 +0100 Subject: [PATCH 03/13] Minimize DOM usage a tiny bit --- .../partials/gallery/thumbnails.blade.php | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/resources/views/product/partials/gallery/thumbnails.blade.php b/resources/views/product/partials/gallery/thumbnails.blade.php index aacdc7207..38f39a68e 100644 --- a/resources/views/product/partials/gallery/thumbnails.blade.php +++ b/resources/views/product/partials/gallery/thumbnails.blade.php @@ -42,29 +42,31 @@ class="block max-h-full w-auto object-contain" height="80" /> -
images) - $imageId - 1) v-cloak @endunless - v-if="images.length - {{ $imageId }} - 1" - > -
+ @endif @endfor From 55ba0c07c5fc585e0c3e3256a1cc1ca3b7608503 Mon Sep 17 00:00:00 2001 From: Jade-GG Date: Wed, 22 Jan 2025 13:42:30 +0000 Subject: [PATCH 04/13] Apply fixes from Duster --- resources/views/product/partials/gallery/thumbnails.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/product/partials/gallery/thumbnails.blade.php b/resources/views/product/partials/gallery/thumbnails.blade.php index 8dab65eb1..4c912c47a 100644 --- a/resources/views/product/partials/gallery/thumbnails.blade.php +++ b/resources/views/product/partials/gallery/thumbnails.blade.php @@ -42,7 +42,7 @@ class="block max-h-full w-auto object-contain" height="80" /> - @if($imageId + 1 >= min($breakpoints)) + @if ($imageId + 1 >= min($breakpoints))
images) - $imageId - 1) v-cloak @endunless v-if="images.length - {{ $imageId }} - 1" From 4b7688e0eed16b3544881c64c34a6b30a5da671c Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Wed, 22 Jan 2025 14:44:02 +0100 Subject: [PATCH 05/13] Improve DOM minification --- resources/views/product/partials/gallery/thumbnails.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/product/partials/gallery/thumbnails.blade.php b/resources/views/product/partials/gallery/thumbnails.blade.php index 4c912c47a..ab8e2d670 100644 --- a/resources/views/product/partials/gallery/thumbnails.blade.php +++ b/resources/views/product/partials/gallery/thumbnails.blade.php @@ -42,7 +42,7 @@ class="block max-h-full w-auto object-contain" height="80" /> - @if ($imageId + 1 >= min($breakpoints)) + @if (in_array($imageId + 1, $breakpoints))
images) - $imageId - 1) v-cloak @endunless v-if="images.length - {{ $imageId }} - 1" From fdefb213f6136687cb5cfcb2be9872528435e597 Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Wed, 22 Jan 2025 14:53:26 +0100 Subject: [PATCH 06/13] Move showMore to separate partial --- .../partials/gallery/thumbnails.blade.php | 29 ++----------------- .../gallery/thumbnails/showMore.blade.php | 25 ++++++++++++++++ 2 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 resources/views/product/partials/gallery/thumbnails/showMore.blade.php diff --git a/resources/views/product/partials/gallery/thumbnails.blade.php b/resources/views/product/partials/gallery/thumbnails.blade.php index ab8e2d670..218f05909 100644 --- a/resources/views/product/partials/gallery/thumbnails.blade.php +++ b/resources/views/product/partials/gallery/thumbnails.blade.php @@ -31,7 +31,7 @@ v-on:click="change({{ $imageId }})" > images)) src="/storage/{{ config('rapidez.store') }}/resizes/80x80/magento/catalog/product/{{ $product->images[$imageId] }}.webp" @endif @@ -42,31 +42,8 @@ class="block max-h-full w-auto object-contain" height="80" /> - @if (in_array($imageId + 1, $breakpoints)) -
images) - $imageId - 1) v-cloak @endunless - v-if="images.length - {{ $imageId }} - 1" - > - -
- @endif + {{-- Only include the showMore if it's actually possible to be visible --}} + @includeWhen(in_array($imageId + 1, $breakpoints), 'rapidez::product.partials.gallery.thumbnails.showMore') @endfor
diff --git a/resources/views/product/partials/gallery/thumbnails/showMore.blade.php b/resources/views/product/partials/gallery/thumbnails/showMore.blade.php new file mode 100644 index 000000000..d231a84e6 --- /dev/null +++ b/resources/views/product/partials/gallery/thumbnails/showMore.blade.php @@ -0,0 +1,25 @@ +{{-- This component shows an overlay on the last shown thumbnail if there are more thumbnails after it. --}} + +
images) - $imageId - 1) v-cloak @endunless + v-if="images.length - {{ $imageId }} - 1" +> + +
From 22877ee12c82567797870bd598c90eac5e089d77 Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Wed, 22 Jan 2025 14:57:51 +0100 Subject: [PATCH 07/13] Update language --- resources/views/product/partials/gallery/thumbnails.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/product/partials/gallery/thumbnails.blade.php b/resources/views/product/partials/gallery/thumbnails.blade.php index 218f05909..3d2149509 100644 --- a/resources/views/product/partials/gallery/thumbnails.blade.php +++ b/resources/views/product/partials/gallery/thumbnails.blade.php @@ -1,5 +1,5 @@ {{-- - In this file we avoid layout shifts on the page by pre-populating the possible amount of thumbnail slots. + In this component we avoid layout shifts on the page by pre-populating the possible amount of thumbnail slots. On page load all of the images come from PHP, using `@unless (...) v-cloak @endunless` to hide things that shouldn't be shown, but need a placeholder element. After Vue gets loaded in, it will take over and replace the `v-cloak`s with the `v-if`s, which means that From c81a5d3f1d2024dc01e7e02c239b8e1e1fd495ea Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Thu, 23 Jan 2025 11:04:37 +0100 Subject: [PATCH 08/13] Always show thumbnails, rename show-more --- resources/views/product/partials/gallery/thumbnails.blade.php | 2 +- .../thumbnails/{showMore.blade.php => show-more.blade.php} | 0 resources/views/product/partials/images.blade.php | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename resources/views/product/partials/gallery/thumbnails/{showMore.blade.php => show-more.blade.php} (100%) diff --git a/resources/views/product/partials/gallery/thumbnails.blade.php b/resources/views/product/partials/gallery/thumbnails.blade.php index 3d2149509..214705112 100644 --- a/resources/views/product/partials/gallery/thumbnails.blade.php +++ b/resources/views/product/partials/gallery/thumbnails.blade.php @@ -43,7 +43,7 @@ class="block max-h-full w-auto object-contain" /> {{-- Only include the showMore if it's actually possible to be visible --}} - @includeWhen(in_array($imageId + 1, $breakpoints), 'rapidez::product.partials.gallery.thumbnails.showMore') + @includeWhen(in_array($imageId + 1, $breakpoints), 'rapidez::product.partials.gallery.thumbnails.show-more') @endfor
diff --git a/resources/views/product/partials/gallery/thumbnails/showMore.blade.php b/resources/views/product/partials/gallery/thumbnails/show-more.blade.php similarity index 100% rename from resources/views/product/partials/gallery/thumbnails/showMore.blade.php rename to resources/views/product/partials/gallery/thumbnails/show-more.blade.php diff --git a/resources/views/product/partials/images.blade.php b/resources/views/product/partials/images.blade.php index b83e44148..0d235a9a1 100644 --- a/resources/views/product/partials/images.blade.php +++ b/resources/views/product/partials/images.blade.php @@ -9,7 +9,7 @@
@include('rapidez::product.partials.gallery.slider') - @includeWhen(count($product->images) > 1, 'rapidez::product.partials.gallery.thumbnails') + @include('rapidez::product.partials.gallery.thumbnails')
@include('rapidez::product.partials.gallery.popup') From 6305e635266a0f7bec3782a38021b96e3f2c09cf Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Thu, 23 Jan 2025 11:05:22 +0100 Subject: [PATCH 09/13] Update resources/views/product/partials/gallery/popup.blade.php Co-authored-by: Roy Duineveld --- resources/views/product/partials/gallery/popup.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/product/partials/gallery/popup.blade.php b/resources/views/product/partials/gallery/popup.blade.php index dc2acbbab..1959bbaec 100644 --- a/resources/views/product/partials/gallery/popup.blade.php +++ b/resources/views/product/partials/gallery/popup.blade.php @@ -1,4 +1,4 @@ -
+
Date: Fri, 24 Jan 2025 12:54:19 +0100 Subject: [PATCH 10/13] Replace first v-cloak duo --- .../product/partials/gallery/thumbnails.blade.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/views/product/partials/gallery/thumbnails.blade.php b/resources/views/product/partials/gallery/thumbnails.blade.php index 214705112..3890777c6 100644 --- a/resources/views/product/partials/gallery/thumbnails.blade.php +++ b/resources/views/product/partials/gallery/thumbnails.blade.php @@ -1,7 +1,7 @@ {{-- In this component we avoid layout shifts on the page by pre-populating the possible amount of thumbnail slots. - On page load all of the images come from PHP, using `@unless (...) v-cloak @endunless` to hide things that - shouldn't be shown, but need a placeholder element. + On page load all of the images come from PHP, using `v-cloak` to hide things that shouldn't be shown, but need + a placeholder element. After Vue gets loaded in, it will take over and replace the `v-cloak`s with the `v-if`s, which means that the two conditionals should be identical to avoid layout shifts. @@ -13,8 +13,10 @@
@for ($imageId = 0; $imageId < max($breakpoints); $imageId++) - @endif
- + diff --git a/resources/views/product/partials/gallery/thumbnails.blade.php b/resources/views/product/partials/gallery/thumbnails.blade.php index 3863508e7..dc3197966 100644 --- a/resources/views/product/partials/gallery/thumbnails.blade.php +++ b/resources/views/product/partials/gallery/thumbnails.blade.php @@ -1,11 +1,7 @@ {{-- - In this component we avoid layout shifts on the page by pre-populating the possible amount of thumbnail slots. - On page load all of the images come from PHP, using `v-cloak` to hide things that shouldn't be shown, but need - a placeholder element. - After Vue gets loaded in, it will take over and replace the `v-cloak`s with the `v-if`s, which means that - the two conditionals should be identical to avoid layout shifts. - - The `$breakpoints` variable determines how many images are shown on each individual breakpoint. +This components initializes with data from PHP to avoid layout shifts. +When Vue is loaded it takes over and all `v-cloak`'s show up. +With `$breakpoints` you can control the amount of images. --}} @php($breakpoints = ['xl' => 7, 'lg' => 5, 'md' => 7, 'sm' => 5, 'xs' => 3]) @@ -33,7 +29,7 @@ v-on:click="change({{ $imageId }})" > images)) src="/storage/{{ config('rapidez.store') }}/resizes/80x80/magento/catalog/product/{{ $product->images[$imageId] }}.webp" @endif