Skip to content

Commit

Permalink
Quick fix is prerender changes (#1182)
Browse files Browse the repository at this point in the history
* add prerender to significant props

* add to get visible items (and align to v5's improvements)
  • Loading branch information
yhattav authored Feb 11, 2024
1 parent 10663e2 commit 1897db9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ export class GalleryContainer extends React.Component {
};

const getSignificantProps = (props) => {
const { id, options, container, items, isInDisplay } = props;
return { id, options, container, items, isInDisplay };
const { id, options, container, items, isInDisplay, isPrerenderMode } =
props;
return { id, options, container, items, isInDisplay, isPrerenderMode };
};

if (this.reCreateGalleryTimer) {
Expand Down Expand Up @@ -298,15 +299,17 @@ export class GalleryContainer extends React.Component {
);
}

getVisibleItems(items, container) {
getVisibleItems(items, container, isPrerenderMode) {
const { gotFirstScrollEvent } = this.state;
const scrollY = window.scrollY;
const scrollY = this.state?.scrollPosition?.top || 0;
const { galleryHeight, scrollBase, galleryWidth } = container;
if (
isPrerenderMode || // (used to be isSSR, had a hydrate bug, isPrerenderMode is the way to go in terms of hydrate issues)
isSEOMode() ||
isEditMode() ||
gotFirstScrollEvent ||
scrollY > 0 ||
isPreviewMode() ||
this.props.activeIndex > 0
) {
return items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ class GalleryView extends React.Component {
? 'auto'
: this.props.container.galleryWidth - options.imageMargin;

const items = getVisibleItems(galleryStructure.galleryItems, container);
const items = getVisibleItems(
galleryStructure.galleryItems,
container,
this.props.isPrerenderMode
);
const itemsWithVirtualizationData =
getItemsInViewportOrMarginByScrollLocation({
items,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,17 @@ class SlideshowView extends React.Component {
}

isAllItemsLoaded() {
const { totalItemsCount, getVisibleItems, galleryStructure, container } =
this.props;
const {
totalItemsCount,
getVisibleItems,
galleryStructure,
container,
isPrerenderMode,
} = this.props;
const visibleItemsCount = getVisibleItems(
galleryStructure.galleryItems,
container
container,
isPrerenderMode
).length;
return visibleItemsCount >= totalItemsCount;
}
Expand Down Expand Up @@ -625,9 +631,14 @@ class SlideshowView extends React.Component {

getBufferedItems(galleryGroups, container) {
const { state, props } = this;
const { options, virtualizationSettings, getVisibleItems } = props;
const {
options,
virtualizationSettings,
getVisibleItems,
isPrerenderMode,
} = props;
const { activeIndex } = state;
const groups = getVisibleItems(galleryGroups, container);
const groups = getVisibleItems(galleryGroups, container, isPrerenderMode);
const galleryWidth =
this.props.galleryContainerRef?.clientWidth ||
container.galleryWidth ||
Expand Down

0 comments on commit 1897db9

Please sign in to comment.