Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SSR of cloned slides #444

Merged
merged 7 commits into from
Dec 9, 2024
Merged

Conversation

Tofandel
Copy link
Contributor

@Tofandel Tofandel commented Dec 8, 2024

Superseedes #443

Fixes #442

I added a test for SSR and found an issue with the index calculation of pre cloned slides

@Tofandel Tofandel force-pushed the fix/ssr-clones branch 2 times, most recently from 57338fb to e0d0a77 Compare December 8, 2024 15:32
@Tofandel Tofandel force-pushed the fix/ssr-clones branch 7 times, most recently from 0d07990 to 3a0ba32 Compare December 8, 2024 16:17
@ismail9k
Copy link
Owner

ismail9k commented Dec 8, 2024

Unfortunately the issue still exists
Steps to regenerate the issue:

  1. npm run build
  2. npm run docs:build
  3. npm run docs:serve
  4. visit this link: http://localhost:4173/examples-fallback.html#wrap-around

@Tofandel
Copy link
Contributor Author

Tofandel commented Dec 8, 2024

I can see an edge case where if we have itemsToShow > nb of slides with wraparound, we will not get enough slides in the clones

I'm seeing if we can use a for instead of looping on slides and using a placeholder fragments if we can't find a slide to solve both of this

@Tofandel
Copy link
Contributor Author

Tofandel commented Dec 8, 2024

Found an elegant solution and also checked the docs, it all checks out

</div>"
`;

exports[`SSR Carousel > renders server side properly 2`] = `"<div id="app"><section class="carousel is-ltr" style="" dir="ltr" aria-label="Gallery" tabindex="0"><div class="carousel__viewport"><ol class="carousel__track" style="transform:translateX(0px);"><li style="width:50%;" class="carousel__slide carousel__slide--clone" aria-hidden="true"></li><li style="width:50%;" class="carousel__slide carousel__slide--clone" aria-hidden="true"></li><li style="width:50%;" class="carousel__slide carousel__slide--clone" aria-hidden="true"></li><!--[--><li style="width:50%;" class="carousel__slide carousel__slide--visible carousel__slide--prev" id="v-0">1 <input type="text"></li><li style="width:50%;" class="carousel__slide carousel__slide--visible carousel__slide--active" id="v-1">2 <input type="text"></li><li style="width:50%;" class="carousel__slide carousel__slide--visible carousel__slide--next" id="v-2">3 <input type="text"></li><li style="width:50%;" class="carousel__slide" id="v-3">4 <input type="text"></li><li style="width:50%;" class="carousel__slide" id="v-4">5 <input type="text"></li><!--]--><li style="width:50%;" class="carousel__slide carousel__slide--clone carousel__slide--visible carousel__slide--prev" aria-hidden="true"></li><li style="width:50%;" class="carousel__slide carousel__slide--clone carousel__slide--visible carousel__slide--active" aria-hidden="true"></li><li style="width:50%;" class="carousel__slide carousel__slide--clone carousel__slide--visible carousel__slide--next" aria-hidden="true"></li></ol></div><!--[--><!--[--><button type="button" class="carousel__prev" aria-label="Navigate to previous slide" title="Navigate to previous slide"><svg class="carousel__icon" viewBox="0 0 24 24" role="img" aria-label="Arrow pointing to the left"><title>Arrow pointing to the left</title><path d="M15.41 16.59L10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z"></path></svg></button><button type="button" class="carousel__next" aria-label="Navigate to next slide" title="Navigate to next slide"><svg class="carousel__icon" viewBox="0 0 24 24" role="img" aria-label="Arrow pointing to the right"><title>Arrow pointing to the right</title><path d="M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z"></path></svg></button><!--]--><ol class="carousel__pagination"><li class="carousel__pagination-item"><button type="button" class="carousel__pagination-button" aria-label="Navigate to slide 1" aria-pressed="false" aria-controls="v-0" title="Navigate to slide 1"></button></li><li class="carousel__pagination-item"><button type="button" class="carousel__pagination-button carousel__pagination-button--active" aria-label="Navigate to slide 2" aria-pressed="true" aria-controls="v-1" title="Navigate to slide 2"></button></li><li class="carousel__pagination-item"><button type="button" class="carousel__pagination-button" aria-label="Navigate to slide 3" aria-pressed="false" aria-controls="v-2" title="Navigate to slide 3"></button></li><li class="carousel__pagination-item"><button type="button" class="carousel__pagination-button" aria-label="Navigate to slide 4" aria-pressed="false" aria-controls="v-3" title="Navigate to slide 4"></button></li><li class="carousel__pagination-item"><button type="button" class="carousel__pagination-button" aria-label="Navigate to slide 5" aria-pressed="false" aria-controls="v-4" title="Navigate to slide 5"></button></li></ol><!--]--><div class="carousel__liveregion carousel__sr-only" aria-live="polite" aria-atomic="true">Item 2 of 5</div></section></div>"`;
Copy link
Contributor Author

@Tofandel Tofandel Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SSR now doesn't contain the content of the cloned slide but this doesn't trigger a mismatch because the node is properly hydrated with it's key and so it can then be properly updated when slides.length > 0

It would be possible to add the getSlidesVNodes now to have the content in SSR for slides not within components as well as it won't trigger a mismatch but that means a different behavior if slotted or not, and that might lead to confusion

Copy link
Owner

@ismail9k ismail9k Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #443, I implemented the generation of only the cloned slides from getSlidesVNodes, leaving the component-based ones unchanged. However, your approach of falling back to an empty slide offers a more consistent and predictable behavior. I appreciate the simplicity and clarity it brings to the implementation. I’ll go ahead with releasing this update and gather feedback from the community to ensure it aligns with their expectations.

@Tofandel Tofandel force-pushed the fix/ssr-clones branch 6 times, most recently from bf897b6 to f6fff36 Compare December 8, 2024 22:12
@ismail9k ismail9k merged commit ce4f211 into ismail9k:master Dec 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cloned Slides Not Rendered Correctly
2 participants