Skip to content

Commit ab9fa7e

Browse files
author
Jannick Garthen
committed
fix(ViewportProvider): ensure to not initialise components when collector is not ready yet
1 parent f440a3d commit ab9fa7e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/ViewportCollector.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export default class ViewportCollector extends React.PureComponent<IProps> {
179179
private scrollMightHaveUpdated: boolean;
180180
private resizeMightHaveUpdated: boolean;
181181
private resizeObserver: ResizeObserver | null;
182+
public syncedStateOnce: boolean;
182183

183184
constructor(props: IProps) {
184185
super(props);
@@ -192,6 +193,7 @@ export default class ViewportCollector extends React.PureComponent<IProps> {
192193
this.lastSyncedDimensionsState = { ...this.dimensionsState };
193194
this.lastSyncedScrollState = { ...this.scrollState };
194195
this.resizeObserver = null;
196+
this.syncedStateOnce = false;
195197
}
196198

197199
componentDidMount() {
@@ -272,6 +274,9 @@ export default class ViewportCollector extends React.PureComponent<IProps> {
272274
);
273275

274276
syncState = () => {
277+
if (!this.syncedStateOnce) {
278+
this.syncedStateOnce = true;
279+
}
275280
if (this.scrollMightHaveUpdated) {
276281
Object.assign(this.scrollState, getClientScroll(this.scrollState));
277282
}

lib/ViewportProvider.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export default class ViewportProvider extends React.PureComponent<
252252
this.initializeListenersTick = requestAnimationFrame(() => {
253253
if (
254254
this.collector.current &&
255+
this.collector.current.syncedStateOnce &&
255256
this.listeners.some(l => !l.initialized)
256257
) {
257258
this.triggerUpdateToListeners(
@@ -278,10 +279,10 @@ export default class ViewportProvider extends React.PureComponent<
278279
removeViewportChangeListener: this.removeViewportChangeListener,
279280
scheduleReinitializeChangeHandler: this.scheduleReinitializeChangeHandler,
280281
getCurrentViewport: () => {
281-
if (!this.collector.current) {
282-
return this.getCurrentDefaultViewport();
282+
if (this.collector.current && this.collector.current.syncedStateOnce) {
283+
return this.collector.current.getPropsFromState();
283284
}
284-
return this.collector.current.getPropsFromState();
285+
return this.getCurrentDefaultViewport();
285286
},
286287
hasRootProviderAsParent: true,
287288
version: '__VERSION__',

0 commit comments

Comments
 (0)