@react-aria/virtualizer 3.10.2-nightly.4658 → 3.10.2-nightly.4664

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,7 +32,6 @@ $parcel$export(module.exports, "ScrollView", () => $00ca8c0b29e3e07c$export$5665
32
32
 
33
33
 
34
34
 
35
- let $00ca8c0b29e3e07c$var$isOldReact = (0, ($parcel$interopDefault($kvIfm$react))).version.startsWith('16.') || (0, ($parcel$interopDefault($kvIfm$react))).version.startsWith('17.');
36
35
  function $00ca8c0b29e3e07c$var$ScrollView(props, ref) {
37
36
  let { contentSize: contentSize, onVisibleRectChange: onVisibleRectChange, children: children, innerStyle: innerStyle, sizeToFit: sizeToFit, onScrollStart: onScrollStart, onScrollEnd: onScrollEnd, scrollDirection: scrollDirection = 'both', ...otherProps } = props;
38
37
  let defaultRef = (0, $kvIfm$react.useRef)();
@@ -94,14 +93,16 @@ function $00ca8c0b29e3e07c$var$ScrollView(props, ref) {
94
93
  };
95
94
  // eslint-disable-next-line react-hooks/exhaustive-deps
96
95
  }, []);
97
- let updateSize = (0, $kvIfm$react.useCallback)(()=>{
96
+ let updateSize = (0, $kvIfm$reactariautils.useEffectEvent)((flush)=>{
98
97
  let dom = ref.current;
99
98
  if (!dom) return;
100
99
  let isTestEnv = false;
101
100
  let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');
102
101
  let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');
103
- let w = isTestEnv && !isClientWidthMocked ? Infinity : dom.clientWidth;
104
- let h = isTestEnv && !isClientHeightMocked ? Infinity : dom.clientHeight;
102
+ let clientWidth = dom.clientWidth;
103
+ let clientHeight = dom.clientHeight;
104
+ let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;
105
+ let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;
105
106
  if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {
106
107
  if (sizeToFit === 'width') w = Math.min(w, contentSize.width);
107
108
  else if (sizeToFit === 'height') h = Math.min(h, contentSize.height);
@@ -109,41 +110,44 @@ function $00ca8c0b29e3e07c$var$ScrollView(props, ref) {
109
110
  if (state.width !== w || state.height !== h) {
110
111
  state.width = w;
111
112
  state.height = h;
112
- onVisibleRectChange(new (0, $kvIfm$reactstatelyvirtualizer.Rect)(state.scrollLeft, state.scrollTop, w, h));
113
+ flush(()=>{
114
+ onVisibleRectChange(new (0, $kvIfm$reactstatelyvirtualizer.Rect)(state.scrollLeft, state.scrollTop, w, h));
115
+ });
116
+ // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as
117
+ // a result of the layout update. In this case, re-layout again to account for the
118
+ // adjusted space. In very specific cases this might result in the scrollbars disappearing
119
+ // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid
120
+ // an infinite loop. This matches how browsers behavior with native CSS grid layout.
121
+ if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {
122
+ state.width = dom.clientWidth;
123
+ state.height = dom.clientHeight;
124
+ flush(()=>{
125
+ onVisibleRectChange(new (0, $kvIfm$reactstatelyvirtualizer.Rect)(state.scrollLeft, state.scrollTop, state.width, state.height));
126
+ });
127
+ }
113
128
  }
114
- }, [
115
- onVisibleRectChange,
116
- ref,
117
- state,
118
- sizeToFit,
119
- contentSize
120
- ]);
129
+ });
121
130
  (0, $kvIfm$reactariautils.useLayoutEffect)(()=>{
122
- updateSize();
131
+ // React doesn't allow flushSync inside effects so pass an identity function instead.
132
+ // This only happens on initial render. The resize observer will also call updateSize
133
+ // once it initializes, but we need earlier initialization in a layout effect to avoid
134
+ // a flash of missing content.
135
+ updateSize((fn)=>fn());
123
136
  }, [
124
137
  updateSize
125
138
  ]);
126
- let raf = (0, $kvIfm$react.useRef)();
127
139
  let onResize = (0, $kvIfm$react.useCallback)(()=>{
128
- var _raf;
129
- var _current;
130
- if ($00ca8c0b29e3e07c$var$isOldReact) (_current = (_raf = raf).current) !== null && _current !== void 0 ? _current : _raf.current = requestAnimationFrame(()=>{
131
- updateSize();
132
- raf.current = null;
133
- });
134
- else updateSize();
140
+ updateSize((0, $kvIfm$reactdom.flushSync));
135
141
  }, [
136
142
  updateSize
137
143
  ]);
144
+ // Watch border-box instead of of content-box so that we don't go into
145
+ // an infinite loop when scrollbars appear or disappear.
138
146
  (0, $kvIfm$reactariautils.useResizeObserver)({
139
147
  ref: ref,
148
+ box: 'border-box',
140
149
  onResize: onResize
141
150
  });
142
- (0, $kvIfm$react.useEffect)(()=>{
143
- return ()=>{
144
- if (raf.current) cancelAnimationFrame(raf.current);
145
- };
146
- }, []);
147
151
  let style = {
148
152
  // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.
149
153
  padding: 0,
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA4Bb,IAAI,mCAAa,CAAA,GAAA,sCAAI,EAAE,OAAO,CAAC,UAAU,CAAC,UAAU,CAAA,GAAA,sCAAI,EAAE,OAAO,CAAC,UAAU,CAAC;AAE7E,SAAS,iCAAW,KAAsB,EAAE,GAA8B;IACxE,IAAI,eACF,WAAW,uBACX,mBAAmB,YACnB,QAAQ,cACR,UAAU,aACV,SAAS,iBACT,aAAa,eACb,WAAW,mBACX,kBAAkB,QAClB,GAAG,YACJ,GAAG;IAEJ,IAAI,aAAa,CAAA,GAAA,mBAAK;IACtB,MAAM,OAAO;IACb,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAE;QACjB,WAAW;QACX,YAAY;QACZ,eAAe;QACf,eAAe;QACf,OAAO;QACP,QAAQ;QACR,aAAa;IACf,GAAG,OAAO;IACV,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAE1B,IAAI,CAAC,aAAa,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC3C,IAAI,WAAW,CAAA,GAAA,wBAAU,EA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,GAAG,EAAE;IAEL,IAAI,QAA6B;QAC/B,iGAAiG;QACjG,SAAS;QACT,GAAG,WAAW,KAAK;IACrB;IAEA,IAAI,oBAAoB,cAAc;QACpC,MAAM,SAAS,GAAG;QAClB,MAAM,SAAS,GAAG;IACpB,OAAO,IAAI,oBAAoB,cAAc,YAAY,KAAK,KAAK,MAAM,KAAK,EAAE;QAC9E,mFAAmF;QACnF,6FAA6F;QAC7F,iFAAiF;QACjF,MAAM,SAAS,GAAG;QAClB,MAAM,SAAS,GAAG;IACpB,OACE,MAAM,QAAQ,GAAG;IAGnB,aAAa;QACX,OAAO,OAAO,QAAQ,CAAC,YAAY,KAAK,IAAI,YAAY,KAAK,GAAG;QAChE,QAAQ,OAAO,QAAQ,CAAC,YAAY,MAAM,IAAI,YAAY,MAAM,GAAG;QACnE,eAAe,cAAc,SAAS;QACtC,UAAU;QACV,GAAG,UAAU;IACf;IAEA,qBACE,0DAAC;QAAI,MAAK;QAAgB,GAAG,UAAU;QAAE,OAAO;QAAO,KAAK;QAAK,UAAU;qBACzE,0DAAC;QAAI,MAAK;QAAe,OAAO;OAC7B;AAIT;AAEA,MAAM,yDAAuB,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC","sources":["packages/@react-aria/virtualizer/src/ScrollView.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// @ts-ignore\nimport {flushSync} from 'react-dom';\nimport {getScrollLeft} from './utils';\nimport React, {\n CSSProperties,\n HTMLAttributes,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\nimport {Rect, Size} from '@react-stately/virtualizer';\nimport {useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface ScrollViewProps extends HTMLAttributes<HTMLElement> {\n contentSize: Size,\n onVisibleRectChange: (rect: Rect) => void,\n children: ReactNode,\n innerStyle?: CSSProperties,\n sizeToFit?: 'width' | 'height',\n onScrollStart?: () => void,\n onScrollEnd?: () => void,\n scrollDirection?: 'horizontal' | 'vertical' | 'both'\n}\n\nlet isOldReact = React.version.startsWith('16.') || React.version.startsWith('17.');\n\nfunction ScrollView(props: ScrollViewProps, ref: RefObject<HTMLDivElement>) {\n let {\n contentSize,\n onVisibleRectChange,\n children,\n innerStyle,\n sizeToFit,\n onScrollStart,\n onScrollEnd,\n scrollDirection = 'both',\n ...otherProps\n } = props;\n\n let defaultRef = useRef();\n ref = ref || defaultRef;\n let state = useRef({\n scrollTop: 0,\n scrollLeft: 0,\n scrollEndTime: 0,\n scrollTimeout: null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n let onScroll = useCallback((e) => {\n if (e.target !== e.currentTarget) {\n return;\n }\n\n if (props.onScroll) {\n props.onScroll(e);\n }\n\n flushSync(() => {\n let scrollTop = e.currentTarget.scrollTop;\n let scrollLeft = getScrollLeft(e.currentTarget, direction);\n\n // Prevent rubber band scrolling from shaking when scrolling out of bounds\n state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));\n state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));\n\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n\n if (!state.isScrolling) {\n state.isScrolling = true;\n setScrolling(true);\n\n if (onScrollStart) {\n onScrollStart();\n }\n }\n\n // So we don't constantly call clearTimeout and setTimeout,\n // keep track of the current timeout time and only reschedule\n // the timer when it is getting close.\n let now = Date.now();\n if (state.scrollEndTime <= now + 50) {\n state.scrollEndTime = now + 300;\n\n clearTimeout(state.scrollTimeout);\n state.scrollTimeout = setTimeout(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n if (onScrollEnd) {\n onScrollEnd();\n }\n }, 300);\n }\n });\n }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n clearTimeout(state.scrollTimeout);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let updateSize = useCallback(() => {\n let dom = ref.current;\n if (!dom) {\n return;\n }\n\n let isTestEnv = process.env.NODE_ENV === 'test' && !process.env.VIRT_ON;\n let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');\n let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');\n let w = isTestEnv && !isClientWidthMocked ? Infinity : dom.clientWidth;\n let h = isTestEnv && !isClientHeightMocked ? Infinity : dom.clientHeight;\n\n if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {\n if (sizeToFit === 'width') {\n w = Math.min(w, contentSize.width);\n } else if (sizeToFit === 'height') {\n h = Math.min(h, contentSize.height);\n }\n }\n\n if (state.width !== w || state.height !== h) {\n state.width = w;\n state.height = h;\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, w, h));\n }\n }, [onVisibleRectChange, ref, state, sizeToFit, contentSize]);\n\n useLayoutEffect(() => {\n updateSize();\n }, [updateSize]);\n let raf = useRef<ReturnType<typeof requestAnimationFrame> | null>();\n let onResize = useCallback(() => {\n if (isOldReact) {\n raf.current ??= requestAnimationFrame(() => {\n updateSize();\n raf.current = null;\n });\n } else {\n updateSize();\n }\n }, [updateSize]);\n useResizeObserver({ref, onResize});\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, []);\n\n let style: React.CSSProperties = {\n // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.\n padding: 0,\n ...otherProps.style\n };\n\n if (scrollDirection === 'horizontal') {\n style.overflowX = 'auto';\n style.overflowY = 'hidden';\n } else if (scrollDirection === 'vertical' || contentSize.width === state.width) {\n // Set overflow-x: hidden if content size is equal to the width of the scroll view.\n // This prevents horizontal scrollbars from flickering during resizing due to resize observer\n // firing slower than the frame rate, which may cause an infinite re-render loop.\n style.overflowY = 'auto';\n style.overflowX = 'hidden';\n } else {\n style.overflow = 'auto';\n }\n\n innerStyle = {\n width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,\n height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,\n pointerEvents: isScrolling ? 'none' : 'auto',\n position: 'relative',\n ...innerStyle\n };\n\n return (\n <div role=\"presentation\" {...otherProps} style={style} ref={ref} onScroll={onScroll}>\n <div role=\"presentation\" style={innerStyle}>\n {children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef = React.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n"],"names":[],"version":3,"file":"ScrollView.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA4Bb,SAAS,iCAAW,KAAsB,EAAE,GAA8B;IACxE,IAAI,eACF,WAAW,uBACX,mBAAmB,YACnB,QAAQ,cACR,UAAU,aACV,SAAS,iBACT,aAAa,eACb,WAAW,mBACX,kBAAkB,QAClB,GAAG,YACJ,GAAG;IAEJ,IAAI,aAAa,CAAA,GAAA,mBAAK;IACtB,MAAM,OAAO;IACb,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAE;QACjB,WAAW;QACX,YAAY;QACZ,eAAe;QACf,eAAe;QACf,OAAO;QACP,QAAQ;QACR,aAAa;IACf,GAAG,OAAO;IACV,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAE1B,IAAI,CAAC,aAAa,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE;IA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AAA,GAAA,qCAAc,EAAE;QACd,qFAAqF;QACrF,qFAAqF;QACrF,sFAAsF;QACtF,8BAA8B;QAC9B,WAAW,CAAA,KAAM;IACnB,GAAG;QAAC;KAAW;IACf,IAAI,WAAW,CAAA,GAAA,wBAAU,EAAE;QACzB,WAAW,CAAA,GAAA,yBAAQ;IACrB,GAAG;QAAC;KAAW;IACf,sEAAsE;IACtE,wDAAwD;IACxD,CAAA,GAAA,uCAAgB,EAAE;aAAC;QAAK,KAAK;kBAAc;IAAQ;IAEnD,IAAI,QAA6B;QAC/B,iGAAiG;QACjG,SAAS;QACT,GAAG,WAAW,KAAK;IACrB;IAEA,IAAI,oBAAoB,cAAc;QACpC,MAAM,SAAS,GAAG;QAClB,MAAM,SAAS,GAAG;IACpB,OAAO,IAAI,oBAAoB,cAAc,YAAY,KAAK,KAAK,MAAM,KAAK,EAAE;QAC9E,mFAAmF;QACnF,6FAA6F;QAC7F,iFAAiF;QACjF,MAAM,SAAS,GAAG;QAClB,MAAM,SAAS,GAAG;IACpB,OACE,MAAM,QAAQ,GAAG;IAGnB,aAAa;QACX,OAAO,OAAO,QAAQ,CAAC,YAAY,KAAK,IAAI,YAAY,KAAK,GAAG;QAChE,QAAQ,OAAO,QAAQ,CAAC,YAAY,MAAM,IAAI,YAAY,MAAM,GAAG;QACnE,eAAe,cAAc,SAAS;QACtC,UAAU;QACV,GAAG,UAAU;IACf;IAEA,qBACE,0DAAC;QAAI,MAAK;QAAgB,GAAG,UAAU;QAAE,OAAO;QAAO,KAAK;QAAK,UAAU;qBACzE,0DAAC;QAAI,MAAK;QAAe,OAAO;OAC7B;AAIT;AAEA,MAAM,yDAAuB,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC","sources":["packages/@react-aria/virtualizer/src/ScrollView.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// @ts-ignore\nimport {flushSync} from 'react-dom';\nimport {getScrollLeft} from './utils';\nimport React, {\n CSSProperties,\n HTMLAttributes,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\nimport {Rect, Size} from '@react-stately/virtualizer';\nimport {useEffectEvent, useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface ScrollViewProps extends HTMLAttributes<HTMLElement> {\n contentSize: Size,\n onVisibleRectChange: (rect: Rect) => void,\n children: ReactNode,\n innerStyle?: CSSProperties,\n sizeToFit?: 'width' | 'height',\n onScrollStart?: () => void,\n onScrollEnd?: () => void,\n scrollDirection?: 'horizontal' | 'vertical' | 'both'\n}\n\nfunction ScrollView(props: ScrollViewProps, ref: RefObject<HTMLDivElement>) {\n let {\n contentSize,\n onVisibleRectChange,\n children,\n innerStyle,\n sizeToFit,\n onScrollStart,\n onScrollEnd,\n scrollDirection = 'both',\n ...otherProps\n } = props;\n\n let defaultRef = useRef();\n ref = ref || defaultRef;\n let state = useRef({\n scrollTop: 0,\n scrollLeft: 0,\n scrollEndTime: 0,\n scrollTimeout: null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n let onScroll = useCallback((e) => {\n if (e.target !== e.currentTarget) {\n return;\n }\n\n if (props.onScroll) {\n props.onScroll(e);\n }\n\n flushSync(() => {\n let scrollTop = e.currentTarget.scrollTop;\n let scrollLeft = getScrollLeft(e.currentTarget, direction);\n\n // Prevent rubber band scrolling from shaking when scrolling out of bounds\n state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));\n state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));\n\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n\n if (!state.isScrolling) {\n state.isScrolling = true;\n setScrolling(true);\n\n if (onScrollStart) {\n onScrollStart();\n }\n }\n\n // So we don't constantly call clearTimeout and setTimeout,\n // keep track of the current timeout time and only reschedule\n // the timer when it is getting close.\n let now = Date.now();\n if (state.scrollEndTime <= now + 50) {\n state.scrollEndTime = now + 300;\n\n clearTimeout(state.scrollTimeout);\n state.scrollTimeout = setTimeout(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n if (onScrollEnd) {\n onScrollEnd();\n }\n }, 300);\n }\n });\n }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n clearTimeout(state.scrollTimeout);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let updateSize = useEffectEvent((flush: typeof flushSync) => {\n let dom = ref.current;\n if (!dom) {\n return;\n }\n\n let isTestEnv = process.env.NODE_ENV === 'test' && !process.env.VIRT_ON;\n let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');\n let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');\n let clientWidth = dom.clientWidth;\n let clientHeight = dom.clientHeight;\n let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;\n let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;\n\n if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {\n if (sizeToFit === 'width') {\n w = Math.min(w, contentSize.width);\n } else if (sizeToFit === 'height') {\n h = Math.min(h, contentSize.height);\n }\n }\n\n if (state.width !== w || state.height !== h) {\n state.width = w;\n state.height = h;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, w, h));\n });\n\n // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as\n // a result of the layout update. In this case, re-layout again to account for the\n // adjusted space. In very specific cases this might result in the scrollbars disappearing\n // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid\n // an infinite loop. This matches how browsers behavior with native CSS grid layout.\n if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {\n state.width = dom.clientWidth;\n state.height = dom.clientHeight;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n });\n }\n }\n });\n\n useLayoutEffect(() => {\n // React doesn't allow flushSync inside effects so pass an identity function instead.\n // This only happens on initial render. The resize observer will also call updateSize\n // once it initializes, but we need earlier initialization in a layout effect to avoid\n // a flash of missing content.\n updateSize(fn => fn());\n }, [updateSize]);\n let onResize = useCallback(() => {\n updateSize(flushSync);\n }, [updateSize]);\n // Watch border-box instead of of content-box so that we don't go into\n // an infinite loop when scrollbars appear or disappear.\n useResizeObserver({ref, box: 'border-box', onResize});\n\n let style: React.CSSProperties = {\n // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.\n padding: 0,\n ...otherProps.style\n };\n\n if (scrollDirection === 'horizontal') {\n style.overflowX = 'auto';\n style.overflowY = 'hidden';\n } else if (scrollDirection === 'vertical' || contentSize.width === state.width) {\n // Set overflow-x: hidden if content size is equal to the width of the scroll view.\n // This prevents horizontal scrollbars from flickering during resizing due to resize observer\n // firing slower than the frame rate, which may cause an infinite re-render loop.\n style.overflowY = 'auto';\n style.overflowX = 'hidden';\n } else {\n style.overflow = 'auto';\n }\n\n innerStyle = {\n width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,\n height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,\n pointerEvents: isScrolling ? 'none' : 'auto',\n position: 'relative',\n ...innerStyle\n };\n\n return (\n <div role=\"presentation\" {...otherProps} style={style} ref={ref} onScroll={onScroll}>\n <div role=\"presentation\" style={innerStyle}>\n {children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef = React.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n"],"names":[],"version":3,"file":"ScrollView.main.js.map"}
@@ -2,7 +2,7 @@ import {getScrollLeft as $ce415dc67314b753$export$1389d168952b34b5} from "./util
2
2
  import {flushSync as $f9kpT$flushSync} from "react-dom";
3
3
  import $f9kpT$react, {useRef as $f9kpT$useRef, useState as $f9kpT$useState, useCallback as $f9kpT$useCallback, useEffect as $f9kpT$useEffect} from "react";
4
4
  import {Rect as $f9kpT$Rect} from "@react-stately/virtualizer";
5
- import {useLayoutEffect as $f9kpT$useLayoutEffect, useResizeObserver as $f9kpT$useResizeObserver} from "@react-aria/utils";
5
+ import {useEffectEvent as $f9kpT$useEffectEvent, useLayoutEffect as $f9kpT$useLayoutEffect, useResizeObserver as $f9kpT$useResizeObserver} from "@react-aria/utils";
6
6
  import {useLocale as $f9kpT$useLocale} from "@react-aria/i18n";
7
7
 
8
8
  /*
@@ -22,7 +22,6 @@ import {useLocale as $f9kpT$useLocale} from "@react-aria/i18n";
22
22
 
23
23
 
24
24
 
25
- let $44a6ee657928b002$var$isOldReact = (0, $f9kpT$react).version.startsWith('16.') || (0, $f9kpT$react).version.startsWith('17.');
26
25
  function $44a6ee657928b002$var$ScrollView(props, ref) {
27
26
  let { contentSize: contentSize, onVisibleRectChange: onVisibleRectChange, children: children, innerStyle: innerStyle, sizeToFit: sizeToFit, onScrollStart: onScrollStart, onScrollEnd: onScrollEnd, scrollDirection: scrollDirection = 'both', ...otherProps } = props;
28
27
  let defaultRef = (0, $f9kpT$useRef)();
@@ -84,14 +83,16 @@ function $44a6ee657928b002$var$ScrollView(props, ref) {
84
83
  };
85
84
  // eslint-disable-next-line react-hooks/exhaustive-deps
86
85
  }, []);
87
- let updateSize = (0, $f9kpT$useCallback)(()=>{
86
+ let updateSize = (0, $f9kpT$useEffectEvent)((flush)=>{
88
87
  let dom = ref.current;
89
88
  if (!dom) return;
90
89
  let isTestEnv = false;
91
90
  let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');
92
91
  let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');
93
- let w = isTestEnv && !isClientWidthMocked ? Infinity : dom.clientWidth;
94
- let h = isTestEnv && !isClientHeightMocked ? Infinity : dom.clientHeight;
92
+ let clientWidth = dom.clientWidth;
93
+ let clientHeight = dom.clientHeight;
94
+ let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;
95
+ let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;
95
96
  if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {
96
97
  if (sizeToFit === 'width') w = Math.min(w, contentSize.width);
97
98
  else if (sizeToFit === 'height') h = Math.min(h, contentSize.height);
@@ -99,41 +100,44 @@ function $44a6ee657928b002$var$ScrollView(props, ref) {
99
100
  if (state.width !== w || state.height !== h) {
100
101
  state.width = w;
101
102
  state.height = h;
102
- onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, w, h));
103
+ flush(()=>{
104
+ onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, w, h));
105
+ });
106
+ // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as
107
+ // a result of the layout update. In this case, re-layout again to account for the
108
+ // adjusted space. In very specific cases this might result in the scrollbars disappearing
109
+ // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid
110
+ // an infinite loop. This matches how browsers behavior with native CSS grid layout.
111
+ if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {
112
+ state.width = dom.clientWidth;
113
+ state.height = dom.clientHeight;
114
+ flush(()=>{
115
+ onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, state.width, state.height));
116
+ });
117
+ }
103
118
  }
104
- }, [
105
- onVisibleRectChange,
106
- ref,
107
- state,
108
- sizeToFit,
109
- contentSize
110
- ]);
119
+ });
111
120
  (0, $f9kpT$useLayoutEffect)(()=>{
112
- updateSize();
121
+ // React doesn't allow flushSync inside effects so pass an identity function instead.
122
+ // This only happens on initial render. The resize observer will also call updateSize
123
+ // once it initializes, but we need earlier initialization in a layout effect to avoid
124
+ // a flash of missing content.
125
+ updateSize((fn)=>fn());
113
126
  }, [
114
127
  updateSize
115
128
  ]);
116
- let raf = (0, $f9kpT$useRef)();
117
129
  let onResize = (0, $f9kpT$useCallback)(()=>{
118
- var _raf;
119
- var _current;
120
- if ($44a6ee657928b002$var$isOldReact) (_current = (_raf = raf).current) !== null && _current !== void 0 ? _current : _raf.current = requestAnimationFrame(()=>{
121
- updateSize();
122
- raf.current = null;
123
- });
124
- else updateSize();
130
+ updateSize((0, $f9kpT$flushSync));
125
131
  }, [
126
132
  updateSize
127
133
  ]);
134
+ // Watch border-box instead of of content-box so that we don't go into
135
+ // an infinite loop when scrollbars appear or disappear.
128
136
  (0, $f9kpT$useResizeObserver)({
129
137
  ref: ref,
138
+ box: 'border-box',
130
139
  onResize: onResize
131
140
  });
132
- (0, $f9kpT$useEffect)(()=>{
133
- return ()=>{
134
- if (raf.current) cancelAnimationFrame(raf.current);
135
- };
136
- }, []);
137
141
  let style = {
138
142
  // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.
139
143
  padding: 0,
@@ -2,7 +2,7 @@ import {getScrollLeft as $ce415dc67314b753$export$1389d168952b34b5} from "./util
2
2
  import {flushSync as $f9kpT$flushSync} from "react-dom";
3
3
  import $f9kpT$react, {useRef as $f9kpT$useRef, useState as $f9kpT$useState, useCallback as $f9kpT$useCallback, useEffect as $f9kpT$useEffect} from "react";
4
4
  import {Rect as $f9kpT$Rect} from "@react-stately/virtualizer";
5
- import {useLayoutEffect as $f9kpT$useLayoutEffect, useResizeObserver as $f9kpT$useResizeObserver} from "@react-aria/utils";
5
+ import {useEffectEvent as $f9kpT$useEffectEvent, useLayoutEffect as $f9kpT$useLayoutEffect, useResizeObserver as $f9kpT$useResizeObserver} from "@react-aria/utils";
6
6
  import {useLocale as $f9kpT$useLocale} from "@react-aria/i18n";
7
7
 
8
8
  /*
@@ -22,7 +22,6 @@ import {useLocale as $f9kpT$useLocale} from "@react-aria/i18n";
22
22
 
23
23
 
24
24
 
25
- let $44a6ee657928b002$var$isOldReact = (0, $f9kpT$react).version.startsWith('16.') || (0, $f9kpT$react).version.startsWith('17.');
26
25
  function $44a6ee657928b002$var$ScrollView(props, ref) {
27
26
  let { contentSize: contentSize, onVisibleRectChange: onVisibleRectChange, children: children, innerStyle: innerStyle, sizeToFit: sizeToFit, onScrollStart: onScrollStart, onScrollEnd: onScrollEnd, scrollDirection: scrollDirection = 'both', ...otherProps } = props;
28
27
  let defaultRef = (0, $f9kpT$useRef)();
@@ -84,14 +83,16 @@ function $44a6ee657928b002$var$ScrollView(props, ref) {
84
83
  };
85
84
  // eslint-disable-next-line react-hooks/exhaustive-deps
86
85
  }, []);
87
- let updateSize = (0, $f9kpT$useCallback)(()=>{
86
+ let updateSize = (0, $f9kpT$useEffectEvent)((flush)=>{
88
87
  let dom = ref.current;
89
88
  if (!dom) return;
90
89
  let isTestEnv = false;
91
90
  let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');
92
91
  let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');
93
- let w = isTestEnv && !isClientWidthMocked ? Infinity : dom.clientWidth;
94
- let h = isTestEnv && !isClientHeightMocked ? Infinity : dom.clientHeight;
92
+ let clientWidth = dom.clientWidth;
93
+ let clientHeight = dom.clientHeight;
94
+ let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;
95
+ let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;
95
96
  if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {
96
97
  if (sizeToFit === 'width') w = Math.min(w, contentSize.width);
97
98
  else if (sizeToFit === 'height') h = Math.min(h, contentSize.height);
@@ -99,41 +100,44 @@ function $44a6ee657928b002$var$ScrollView(props, ref) {
99
100
  if (state.width !== w || state.height !== h) {
100
101
  state.width = w;
101
102
  state.height = h;
102
- onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, w, h));
103
+ flush(()=>{
104
+ onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, w, h));
105
+ });
106
+ // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as
107
+ // a result of the layout update. In this case, re-layout again to account for the
108
+ // adjusted space. In very specific cases this might result in the scrollbars disappearing
109
+ // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid
110
+ // an infinite loop. This matches how browsers behavior with native CSS grid layout.
111
+ if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {
112
+ state.width = dom.clientWidth;
113
+ state.height = dom.clientHeight;
114
+ flush(()=>{
115
+ onVisibleRectChange(new (0, $f9kpT$Rect)(state.scrollLeft, state.scrollTop, state.width, state.height));
116
+ });
117
+ }
103
118
  }
104
- }, [
105
- onVisibleRectChange,
106
- ref,
107
- state,
108
- sizeToFit,
109
- contentSize
110
- ]);
119
+ });
111
120
  (0, $f9kpT$useLayoutEffect)(()=>{
112
- updateSize();
121
+ // React doesn't allow flushSync inside effects so pass an identity function instead.
122
+ // This only happens on initial render. The resize observer will also call updateSize
123
+ // once it initializes, but we need earlier initialization in a layout effect to avoid
124
+ // a flash of missing content.
125
+ updateSize((fn)=>fn());
113
126
  }, [
114
127
  updateSize
115
128
  ]);
116
- let raf = (0, $f9kpT$useRef)();
117
129
  let onResize = (0, $f9kpT$useCallback)(()=>{
118
- var _raf;
119
- var _current;
120
- if ($44a6ee657928b002$var$isOldReact) (_current = (_raf = raf).current) !== null && _current !== void 0 ? _current : _raf.current = requestAnimationFrame(()=>{
121
- updateSize();
122
- raf.current = null;
123
- });
124
- else updateSize();
130
+ updateSize((0, $f9kpT$flushSync));
125
131
  }, [
126
132
  updateSize
127
133
  ]);
134
+ // Watch border-box instead of of content-box so that we don't go into
135
+ // an infinite loop when scrollbars appear or disappear.
128
136
  (0, $f9kpT$useResizeObserver)({
129
137
  ref: ref,
138
+ box: 'border-box',
130
139
  onResize: onResize
131
140
  });
132
- (0, $f9kpT$useEffect)(()=>{
133
- return ()=>{
134
- if (raf.current) cancelAnimationFrame(raf.current);
135
- };
136
- }, []);
137
141
  let style = {
138
142
  // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.
139
143
  padding: 0,
@@ -1 +1 @@
1
- {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA4Bb,IAAI,mCAAa,CAAA,GAAA,YAAI,EAAE,OAAO,CAAC,UAAU,CAAC,UAAU,CAAA,GAAA,YAAI,EAAE,OAAO,CAAC,UAAU,CAAC;AAE7E,SAAS,iCAAW,KAAsB,EAAE,GAA8B;IACxE,IAAI,eACF,WAAW,uBACX,mBAAmB,YACnB,QAAQ,cACR,UAAU,aACV,SAAS,iBACT,aAAa,eACb,WAAW,mBACX,kBAAkB,QAClB,GAAG,YACJ,GAAG;IAEJ,IAAI,aAAa,CAAA,GAAA,aAAK;IACtB,MAAM,OAAO;IACb,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAE;QACjB,WAAW;QACX,YAAY;QACZ,eAAe;QACf,eAAe;QACf,OAAO;QACP,QAAQ;QACR,aAAa;IACf,GAAG,OAAO;IACV,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAE1B,IAAI,CAAC,aAAa,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC3C,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE,CAAC;QAC1B,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAC9B;QAGF,IAAI,MAAM,QAAQ,EAChB,MAAM,QAAQ,CAAC;QAGjB,CAAA,GAAA,gBAAQ,EAAE;YACR,IAAI,YAAY,EAAE,aAAa,CAAC,SAAS;YACzC,IAAI,aAAa,CAAA,GAAA,yCAAY,EAAE,EAAE,aAAa,EAAE;YAEh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FAA6F;QAC7F,iFAAiF;QACjF,MAAM,SAAS,GAAG;QAClB,MAAM,SAAS,GAAG;IACpB,OACE,MAAM,QAAQ,GAAG;IAGnB,aAAa;QACX,OAAO,OAAO,QAAQ,CAAC,YAAY,KAAK,IAAI,YAAY,KAAK,GAAG;QAChE,QAAQ,OAAO,QAAQ,CAAC,YAAY,MAAM,IAAI,YAAY,MAAM,GAAG;QACnE,eAAe,cAAc,SAAS;QACtC,UAAU;QACV,GAAG,UAAU;IACf;IAEA,qBACE,gCAAC;QAAI,MAAK;QAAgB,GAAG,UAAU;QAAE,OAAO;QAAO,KAAK;QAAK,UAAU;qBACzE,gCAAC;QAAI,MAAK;QAAe,OAAO;OAC7B;AAIT;AAEA,MAAM,yDAAuB,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC","sources":["packages/@react-aria/virtualizer/src/ScrollView.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// @ts-ignore\nimport {flushSync} from 'react-dom';\nimport {getScrollLeft} from './utils';\nimport React, {\n CSSProperties,\n HTMLAttributes,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\nimport {Rect, Size} from '@react-stately/virtualizer';\nimport {useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface ScrollViewProps extends HTMLAttributes<HTMLElement> {\n contentSize: Size,\n onVisibleRectChange: (rect: Rect) => void,\n children: ReactNode,\n innerStyle?: CSSProperties,\n sizeToFit?: 'width' | 'height',\n onScrollStart?: () => void,\n onScrollEnd?: () => void,\n scrollDirection?: 'horizontal' | 'vertical' | 'both'\n}\n\nlet isOldReact = React.version.startsWith('16.') || React.version.startsWith('17.');\n\nfunction ScrollView(props: ScrollViewProps, ref: RefObject<HTMLDivElement>) {\n let {\n contentSize,\n onVisibleRectChange,\n children,\n innerStyle,\n sizeToFit,\n onScrollStart,\n onScrollEnd,\n scrollDirection = 'both',\n ...otherProps\n } = props;\n\n let defaultRef = useRef();\n ref = ref || defaultRef;\n let state = useRef({\n scrollTop: 0,\n scrollLeft: 0,\n scrollEndTime: 0,\n scrollTimeout: null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n let onScroll = useCallback((e) => {\n if (e.target !== e.currentTarget) {\n return;\n }\n\n if (props.onScroll) {\n props.onScroll(e);\n }\n\n flushSync(() => {\n let scrollTop = e.currentTarget.scrollTop;\n let scrollLeft = getScrollLeft(e.currentTarget, direction);\n\n // Prevent rubber band scrolling from shaking when scrolling out of bounds\n state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));\n state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));\n\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n\n if (!state.isScrolling) {\n state.isScrolling = true;\n setScrolling(true);\n\n if (onScrollStart) {\n onScrollStart();\n }\n }\n\n // So we don't constantly call clearTimeout and setTimeout,\n // keep track of the current timeout time and only reschedule\n // the timer when it is getting close.\n let now = Date.now();\n if (state.scrollEndTime <= now + 50) {\n state.scrollEndTime = now + 300;\n\n clearTimeout(state.scrollTimeout);\n state.scrollTimeout = setTimeout(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n if (onScrollEnd) {\n onScrollEnd();\n }\n }, 300);\n }\n });\n }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n clearTimeout(state.scrollTimeout);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let updateSize = useCallback(() => {\n let dom = ref.current;\n if (!dom) {\n return;\n }\n\n let isTestEnv = process.env.NODE_ENV === 'test' && !process.env.VIRT_ON;\n let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');\n let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');\n let w = isTestEnv && !isClientWidthMocked ? Infinity : dom.clientWidth;\n let h = isTestEnv && !isClientHeightMocked ? Infinity : dom.clientHeight;\n\n if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {\n if (sizeToFit === 'width') {\n w = Math.min(w, contentSize.width);\n } else if (sizeToFit === 'height') {\n h = Math.min(h, contentSize.height);\n }\n }\n\n if (state.width !== w || state.height !== h) {\n state.width = w;\n state.height = h;\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, w, h));\n }\n }, [onVisibleRectChange, ref, state, sizeToFit, contentSize]);\n\n useLayoutEffect(() => {\n updateSize();\n }, [updateSize]);\n let raf = useRef<ReturnType<typeof requestAnimationFrame> | null>();\n let onResize = useCallback(() => {\n if (isOldReact) {\n raf.current ??= requestAnimationFrame(() => {\n updateSize();\n raf.current = null;\n });\n } else {\n updateSize();\n }\n }, [updateSize]);\n useResizeObserver({ref, onResize});\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, []);\n\n let style: React.CSSProperties = {\n // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.\n padding: 0,\n ...otherProps.style\n };\n\n if (scrollDirection === 'horizontal') {\n style.overflowX = 'auto';\n style.overflowY = 'hidden';\n } else if (scrollDirection === 'vertical' || contentSize.width === state.width) {\n // Set overflow-x: hidden if content size is equal to the width of the scroll view.\n // This prevents horizontal scrollbars from flickering during resizing due to resize observer\n // firing slower than the frame rate, which may cause an infinite re-render loop.\n style.overflowY = 'auto';\n style.overflowX = 'hidden';\n } else {\n style.overflow = 'auto';\n }\n\n innerStyle = {\n width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,\n height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,\n pointerEvents: isScrolling ? 'none' : 'auto',\n position: 'relative',\n ...innerStyle\n };\n\n return (\n <div role=\"presentation\" {...otherProps} style={style} ref={ref} onScroll={onScroll}>\n <div role=\"presentation\" style={innerStyle}>\n {children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef = React.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n"],"names":[],"version":3,"file":"ScrollView.module.js.map"}
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAED,aAAa;;;;;;;AA4Bb,SAAS,iCAAW,KAAsB,EAAE,GAA8B;IACxE,IAAI,eACF,WAAW,uBACX,mBAAmB,YACnB,QAAQ,cACR,UAAU,aACV,SAAS,iBACT,aAAa,eACb,WAAW,mBACX,kBAAkB,QAClB,GAAG,YACJ,GAAG;IAEJ,IAAI,aAAa,CAAA,GAAA,aAAK;IACtB,MAAM,OAAO;IACb,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAE;QACjB,WAAW;QACX,YAAY;QACZ,eAAe;QACf,eAAe;QACf,OAAO;QACP,QAAQ;QACR,aAAa;IACf,GAAG,OAAO;IACV,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAE1B,IAAI,CAAC,aAAa,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC3C,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE,CAAC;QAC1B,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAC9B;QAGF,IAAI,MAAM,QAAQ,EAChB,MAAM,QAAQ,CAAC;QAGjB,CAAA,GAAA,gBAAQ,EAAE;YACR,IAAI,YAAY,EAAE,aAAa,CAAC,SAAS;YACzC,IAAI,aAAa,CAAA,GAAA,yCAAY,EAAE,EAAE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BAAgB,EAAE;aAAC;QAAK,KAAK;kBAAc;IAAQ;IAEnD,IAAI,QAA6B;QAC/B,iGAAiG;QACjG,SAAS;QACT,GAAG,WAAW,KAAK;IACrB;IAEA,IAAI,oBAAoB,cAAc;QACpC,MAAM,SAAS,GAAG;QAClB,MAAM,SAAS,GAAG;IACpB,OAAO,IAAI,oBAAoB,cAAc,YAAY,KAAK,KAAK,MAAM,KAAK,EAAE;QAC9E,mFAAmF;QACnF,6FAA6F;QAC7F,iFAAiF;QACjF,MAAM,SAAS,GAAG;QAClB,MAAM,SAAS,GAAG;IACpB,OACE,MAAM,QAAQ,GAAG;IAGnB,aAAa;QACX,OAAO,OAAO,QAAQ,CAAC,YAAY,KAAK,IAAI,YAAY,KAAK,GAAG;QAChE,QAAQ,OAAO,QAAQ,CAAC,YAAY,MAAM,IAAI,YAAY,MAAM,GAAG;QACnE,eAAe,cAAc,SAAS;QACtC,UAAU;QACV,GAAG,UAAU;IACf;IAEA,qBACE,gCAAC;QAAI,MAAK;QAAgB,GAAG,UAAU;QAAE,OAAO;QAAO,KAAK;QAAK,UAAU;qBACzE,gCAAC;QAAI,MAAK;QAAe,OAAO;OAC7B;AAIT;AAEA,MAAM,yDAAuB,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC","sources":["packages/@react-aria/virtualizer/src/ScrollView.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// @ts-ignore\nimport {flushSync} from 'react-dom';\nimport {getScrollLeft} from './utils';\nimport React, {\n CSSProperties,\n HTMLAttributes,\n ReactNode,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\nimport {Rect, Size} from '@react-stately/virtualizer';\nimport {useEffectEvent, useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\ninterface ScrollViewProps extends HTMLAttributes<HTMLElement> {\n contentSize: Size,\n onVisibleRectChange: (rect: Rect) => void,\n children: ReactNode,\n innerStyle?: CSSProperties,\n sizeToFit?: 'width' | 'height',\n onScrollStart?: () => void,\n onScrollEnd?: () => void,\n scrollDirection?: 'horizontal' | 'vertical' | 'both'\n}\n\nfunction ScrollView(props: ScrollViewProps, ref: RefObject<HTMLDivElement>) {\n let {\n contentSize,\n onVisibleRectChange,\n children,\n innerStyle,\n sizeToFit,\n onScrollStart,\n onScrollEnd,\n scrollDirection = 'both',\n ...otherProps\n } = props;\n\n let defaultRef = useRef();\n ref = ref || defaultRef;\n let state = useRef({\n scrollTop: 0,\n scrollLeft: 0,\n scrollEndTime: 0,\n scrollTimeout: null,\n width: 0,\n height: 0,\n isScrolling: false\n }).current;\n let {direction} = useLocale();\n\n let [isScrolling, setScrolling] = useState(false);\n let onScroll = useCallback((e) => {\n if (e.target !== e.currentTarget) {\n return;\n }\n\n if (props.onScroll) {\n props.onScroll(e);\n }\n\n flushSync(() => {\n let scrollTop = e.currentTarget.scrollTop;\n let scrollLeft = getScrollLeft(e.currentTarget, direction);\n\n // Prevent rubber band scrolling from shaking when scrolling out of bounds\n state.scrollTop = Math.max(0, Math.min(scrollTop, contentSize.height - state.height));\n state.scrollLeft = Math.max(0, Math.min(scrollLeft, contentSize.width - state.width));\n\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n\n if (!state.isScrolling) {\n state.isScrolling = true;\n setScrolling(true);\n\n if (onScrollStart) {\n onScrollStart();\n }\n }\n\n // So we don't constantly call clearTimeout and setTimeout,\n // keep track of the current timeout time and only reschedule\n // the timer when it is getting close.\n let now = Date.now();\n if (state.scrollEndTime <= now + 50) {\n state.scrollEndTime = now + 300;\n\n clearTimeout(state.scrollTimeout);\n state.scrollTimeout = setTimeout(() => {\n state.isScrolling = false;\n setScrolling(false);\n state.scrollTimeout = null;\n\n if (onScrollEnd) {\n onScrollEnd();\n }\n }, 300);\n }\n });\n }, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n clearTimeout(state.scrollTimeout);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n let updateSize = useEffectEvent((flush: typeof flushSync) => {\n let dom = ref.current;\n if (!dom) {\n return;\n }\n\n let isTestEnv = process.env.NODE_ENV === 'test' && !process.env.VIRT_ON;\n let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');\n let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');\n let clientWidth = dom.clientWidth;\n let clientHeight = dom.clientHeight;\n let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;\n let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;\n\n if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {\n if (sizeToFit === 'width') {\n w = Math.min(w, contentSize.width);\n } else if (sizeToFit === 'height') {\n h = Math.min(h, contentSize.height);\n }\n }\n\n if (state.width !== w || state.height !== h) {\n state.width = w;\n state.height = h;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, w, h));\n });\n\n // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as\n // a result of the layout update. In this case, re-layout again to account for the\n // adjusted space. In very specific cases this might result in the scrollbars disappearing\n // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid\n // an infinite loop. This matches how browsers behavior with native CSS grid layout.\n if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {\n state.width = dom.clientWidth;\n state.height = dom.clientHeight;\n flush(() => {\n onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));\n });\n }\n }\n });\n\n useLayoutEffect(() => {\n // React doesn't allow flushSync inside effects so pass an identity function instead.\n // This only happens on initial render. The resize observer will also call updateSize\n // once it initializes, but we need earlier initialization in a layout effect to avoid\n // a flash of missing content.\n updateSize(fn => fn());\n }, [updateSize]);\n let onResize = useCallback(() => {\n updateSize(flushSync);\n }, [updateSize]);\n // Watch border-box instead of of content-box so that we don't go into\n // an infinite loop when scrollbars appear or disappear.\n useResizeObserver({ref, box: 'border-box', onResize});\n\n let style: React.CSSProperties = {\n // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.\n padding: 0,\n ...otherProps.style\n };\n\n if (scrollDirection === 'horizontal') {\n style.overflowX = 'auto';\n style.overflowY = 'hidden';\n } else if (scrollDirection === 'vertical' || contentSize.width === state.width) {\n // Set overflow-x: hidden if content size is equal to the width of the scroll view.\n // This prevents horizontal scrollbars from flickering during resizing due to resize observer\n // firing slower than the frame rate, which may cause an infinite re-render loop.\n style.overflowY = 'auto';\n style.overflowX = 'hidden';\n } else {\n style.overflow = 'auto';\n }\n\n innerStyle = {\n width: Number.isFinite(contentSize.width) ? contentSize.width : undefined,\n height: Number.isFinite(contentSize.height) ? contentSize.height : undefined,\n pointerEvents: isScrolling ? 'none' : 'auto',\n position: 'relative',\n ...innerStyle\n };\n\n return (\n <div role=\"presentation\" {...otherProps} style={style} ref={ref} onScroll={onScroll}>\n <div role=\"presentation\" style={innerStyle}>\n {children}\n </div>\n </div>\n );\n}\n\nconst ScrollViewForwardRef = React.forwardRef(ScrollView);\nexport {ScrollViewForwardRef as ScrollView};\n"],"names":[],"version":3,"file":"ScrollView.module.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAcA,4BACI,UAAU,GACV,qBAAqB,GACrB,oBAAoB,CAAC;AAezB,iCAAiC,WAAW,GAAE,OAAe,GAAG,aAAa,CAmC5E;AAED,8BAA8B,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG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C","sources":["packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/utils.ts","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/useVirtualizerItem.ts","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/ScrollView.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/VirtualizerItem.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/Virtualizer.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/index.ts","packages/@react-aria/virtualizer/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {RTLOffsetType} from './utils';\nexport type {VirtualizerItemOptions} from './useVirtualizerItem';\nexport {useVirtualizer, Virtualizer, VirtualizerContext} from './Virtualizer';\nexport {useVirtualizerItem} from './useVirtualizerItem';\nexport {VirtualizerItem, layoutInfoToStyle} from './VirtualizerItem';\nexport {ScrollView} from './ScrollView';\nexport {getRTLOffsetType, getScrollLeft, setScrollLeft} from './utils';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;AAcA,4BACI,UAAU,GACV,qBAAqB,GACrB,oBAAoB,CAAC;AAezB,iCAAiC,WAAW,GAAE,OAAe,GAAG,aAAa,CAmC5E;AAED,8BAA8B,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAkBzE;AAED,8BAA8B,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,QAiBpF;ACz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a,CAAC,EAAE,CACd,MAAM,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,EACjC,YAAY,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,EAChC,QAAQ,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,EAC9B,cAAc,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,YAAY,EAAE,KAC5D,YAAY,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACrB,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAC1B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC/B,eAAe,CAAC,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,CAAC;IACrD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,aAAa,CAAC,EAAE,CAAC,CAAA;CAClB;AAED,OAAO,MAAM,kEAAgF,CAAC;AAqD9F;IACE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;CACxB;AAGD,+BAA+B,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,iBAAiB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC;;;oCAOlH,IAAI;;EA2ClD;AAID,OAAA,MAAM;UAAmH,UAAU,cAAc,CAAC;MAAM,YAAY,CAAC","sources":["packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/utils.ts","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/useVirtualizerItem.ts","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/ScrollView.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/VirtualizerItem.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/Virtualizer.tsx","packages/@react-aria/virtualizer/src/packages/@react-aria/virtualizer/src/index.ts","packages/@react-aria/virtualizer/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {RTLOffsetType} from './utils';\nexport type {VirtualizerItemOptions} from './useVirtualizerItem';\nexport {useVirtualizer, Virtualizer, VirtualizerContext} from './Virtualizer';\nexport {useVirtualizerItem} from './useVirtualizerItem';\nexport {VirtualizerItem, layoutInfoToStyle} from './VirtualizerItem';\nexport {ScrollView} from './ScrollView';\nexport {getRTLOffsetType, getScrollLeft, setScrollLeft} from './utils';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/virtualizer",
3
- "version": "3.10.2-nightly.4658+5548b8925",
3
+ "version": "3.10.2-nightly.4664+10bac541a",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,11 +22,11 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/i18n": "3.0.0-nightly.2946+5548b8925",
26
- "@react-aria/interactions": "3.0.0-nightly.2946+5548b8925",
27
- "@react-aria/utils": "3.0.0-nightly.2946+5548b8925",
28
- "@react-stately/virtualizer": "3.7.2-nightly.4658+5548b8925",
29
- "@react-types/shared": "3.0.0-nightly.2946+5548b8925",
25
+ "@react-aria/i18n": "3.0.0-nightly.2952+10bac541a",
26
+ "@react-aria/interactions": "3.0.0-nightly.2952+10bac541a",
27
+ "@react-aria/utils": "3.0.0-nightly.2952+10bac541a",
28
+ "@react-stately/virtualizer": "3.7.2-nightly.4664+10bac541a",
29
+ "@react-types/shared": "3.0.0-nightly.2952+10bac541a",
30
30
  "@swc/helpers": "^0.5.0"
31
31
  },
32
32
  "peerDependencies": {
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "5548b8925798970db9ffeb1a84049b3afc6bc040"
39
+ "gitHead": "10bac541a2a5c666b443fe70f313455a405a5c77"
40
40
  }
@@ -24,7 +24,7 @@ import React, {
24
24
  useState
25
25
  } from 'react';
26
26
  import {Rect, Size} from '@react-stately/virtualizer';
27
- import {useLayoutEffect, useResizeObserver} from '@react-aria/utils';
27
+ import {useEffectEvent, useLayoutEffect, useResizeObserver} from '@react-aria/utils';
28
28
  import {useLocale} from '@react-aria/i18n';
29
29
 
30
30
  interface ScrollViewProps extends HTMLAttributes<HTMLElement> {
@@ -38,8 +38,6 @@ interface ScrollViewProps extends HTMLAttributes<HTMLElement> {
38
38
  scrollDirection?: 'horizontal' | 'vertical' | 'both'
39
39
  }
40
40
 
41
- let isOldReact = React.version.startsWith('16.') || React.version.startsWith('17.');
42
-
43
41
  function ScrollView(props: ScrollViewProps, ref: RefObject<HTMLDivElement>) {
44
42
  let {
45
43
  contentSize,
@@ -124,7 +122,7 @@ function ScrollView(props: ScrollViewProps, ref: RefObject<HTMLDivElement>) {
124
122
  // eslint-disable-next-line react-hooks/exhaustive-deps
125
123
  }, []);
126
124
 
127
- let updateSize = useCallback(() => {
125
+ let updateSize = useEffectEvent((flush: typeof flushSync) => {
128
126
  let dom = ref.current;
129
127
  if (!dom) {
130
128
  return;
@@ -133,8 +131,10 @@ function ScrollView(props: ScrollViewProps, ref: RefObject<HTMLDivElement>) {
133
131
  let isTestEnv = process.env.NODE_ENV === 'test' && !process.env.VIRT_ON;
134
132
  let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth');
135
133
  let isClientHeightMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientHeight');
136
- let w = isTestEnv && !isClientWidthMocked ? Infinity : dom.clientWidth;
137
- let h = isTestEnv && !isClientHeightMocked ? Infinity : dom.clientHeight;
134
+ let clientWidth = dom.clientWidth;
135
+ let clientHeight = dom.clientHeight;
136
+ let w = isTestEnv && !isClientWidthMocked ? Infinity : clientWidth;
137
+ let h = isTestEnv && !isClientHeightMocked ? Infinity : clientHeight;
138
138
 
139
139
  if (sizeToFit && contentSize.width > 0 && contentSize.height > 0) {
140
140
  if (sizeToFit === 'width') {
@@ -147,32 +147,38 @@ function ScrollView(props: ScrollViewProps, ref: RefObject<HTMLDivElement>) {
147
147
  if (state.width !== w || state.height !== h) {
148
148
  state.width = w;
149
149
  state.height = h;
150
- onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, w, h));
150
+ flush(() => {
151
+ onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, w, h));
152
+ });
153
+
154
+ // If the clientWidth or clientHeight changed, scrollbars appeared or disappeared as
155
+ // a result of the layout update. In this case, re-layout again to account for the
156
+ // adjusted space. In very specific cases this might result in the scrollbars disappearing
157
+ // again, resulting in extra padding. We stop after a maximum of two layout passes to avoid
158
+ // an infinite loop. This matches how browsers behavior with native CSS grid layout.
159
+ if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) {
160
+ state.width = dom.clientWidth;
161
+ state.height = dom.clientHeight;
162
+ flush(() => {
163
+ onVisibleRectChange(new Rect(state.scrollLeft, state.scrollTop, state.width, state.height));
164
+ });
165
+ }
151
166
  }
152
- }, [onVisibleRectChange, ref, state, sizeToFit, contentSize]);
167
+ });
153
168
 
154
169
  useLayoutEffect(() => {
155
- updateSize();
170
+ // React doesn't allow flushSync inside effects so pass an identity function instead.
171
+ // This only happens on initial render. The resize observer will also call updateSize
172
+ // once it initializes, but we need earlier initialization in a layout effect to avoid
173
+ // a flash of missing content.
174
+ updateSize(fn => fn());
156
175
  }, [updateSize]);
157
- let raf = useRef<ReturnType<typeof requestAnimationFrame> | null>();
158
176
  let onResize = useCallback(() => {
159
- if (isOldReact) {
160
- raf.current ??= requestAnimationFrame(() => {
161
- updateSize();
162
- raf.current = null;
163
- });
164
- } else {
165
- updateSize();
166
- }
177
+ updateSize(flushSync);
167
178
  }, [updateSize]);
168
- useResizeObserver({ref, onResize});
169
- useEffect(() => {
170
- return () => {
171
- if (raf.current) {
172
- cancelAnimationFrame(raf.current);
173
- }
174
- };
175
- }, []);
179
+ // Watch border-box instead of of content-box so that we don't go into
180
+ // an infinite loop when scrollbars appear or disappear.
181
+ useResizeObserver({ref, box: 'border-box', onResize});
176
182
 
177
183
  let style: React.CSSProperties = {
178
184
  // Reset padding so that relative positioning works correctly. Padding will be done in JS layout.