@react-aria/virtualizer
Advanced tools
Comparing version 3.0.0-nightly-641446f65-240905 to 3.0.0-nightly-8ab4f20de-240913
@@ -114,5 +114,9 @@ var $efdd61e59e023a1d$exports = require("./utils.main.js"); | ||
}, []); | ||
let isUpdatingSize = (0, $kvIfm$react.useRef)(false); | ||
let updateSize = (0, $kvIfm$reactariautils.useEffectEvent)((flush)=>{ | ||
let dom = ref.current; | ||
if (!dom) return; | ||
if (!dom && !isUpdatingSize.current) return; | ||
// Prevent reentrancy when resize observer fires, triggers re-layout that results in | ||
// content size update, causing below layout effect to fire. This avoids infinite loops. | ||
isUpdatingSize.current = true; | ||
let isTestEnv = false; | ||
@@ -144,26 +148,20 @@ let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth'); | ||
} | ||
isUpdatingSize.current = false; | ||
}); | ||
let didUpdateSize = (0, $kvIfm$react.useRef)(false); | ||
// Update visible rect when the content size changes, in case scrollbars need to appear or disappear. | ||
let lastContentSize = (0, $kvIfm$react.useRef)(null); | ||
(0, $kvIfm$reactariautils.useLayoutEffect)(()=>{ | ||
// React doesn't allow flushSync inside effects, so queue a microtask. | ||
// We also need to wait until all refs are set (e.g. when passing a ref down from a parent). | ||
queueMicrotask(()=>{ | ||
if (!didUpdateSize.current) { | ||
didUpdateSize.current = true; | ||
updateSize((0, $kvIfm$reactdom.flushSync)); | ||
} | ||
}); | ||
}, [ | ||
updateSize | ||
]); | ||
(0, $kvIfm$react.useEffect)(()=>{ | ||
if (!didUpdateSize.current) { | ||
// If useEffect ran before the above microtask, we are in a synchronous render (e.g. act). | ||
// Update the size here so that you don't need to mock timers in tests. | ||
didUpdateSize.current = true; | ||
updateSize((fn)=>fn()); | ||
if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) { | ||
// React doesn't allow flushSync inside effects, so queue a microtask. | ||
// We also need to wait until all refs are set (e.g. when passing a ref down from a parent). | ||
// If we are in an `act` environment, update immediately without a microtask so you don't need | ||
// to mock timers in tests. In this case, the update is synchronous already. | ||
// IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global. | ||
// https://github.com/reactwg/react-18/discussions/102 | ||
// @ts-ignore | ||
if (typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined') updateSize((fn)=>fn()); | ||
else queueMicrotask(()=>updateSize((0, $kvIfm$reactdom.flushSync))); | ||
} | ||
}, [ | ||
updateSize | ||
]); | ||
lastContentSize.current = contentSize; | ||
}); | ||
let onResize = (0, $kvIfm$react.useCallback)(()=>{ | ||
@@ -170,0 +168,0 @@ updateSize((0, $kvIfm$reactdom.flushSync)); |
@@ -103,5 +103,9 @@ import {getScrollLeft as $ce415dc67314b753$export$1389d168952b34b5} from "./utils.module.js"; | ||
}, []); | ||
let isUpdatingSize = (0, $f9kpT$useRef)(false); | ||
let updateSize = (0, $f9kpT$useEffectEvent)((flush)=>{ | ||
let dom = ref.current; | ||
if (!dom) return; | ||
if (!dom && !isUpdatingSize.current) return; | ||
// Prevent reentrancy when resize observer fires, triggers re-layout that results in | ||
// content size update, causing below layout effect to fire. This avoids infinite loops. | ||
isUpdatingSize.current = true; | ||
let isTestEnv = false; | ||
@@ -133,26 +137,20 @@ let isClientWidthMocked = Object.getOwnPropertyNames(window.HTMLElement.prototype).includes('clientWidth'); | ||
} | ||
isUpdatingSize.current = false; | ||
}); | ||
let didUpdateSize = (0, $f9kpT$useRef)(false); | ||
// Update visible rect when the content size changes, in case scrollbars need to appear or disappear. | ||
let lastContentSize = (0, $f9kpT$useRef)(null); | ||
(0, $f9kpT$useLayoutEffect)(()=>{ | ||
// React doesn't allow flushSync inside effects, so queue a microtask. | ||
// We also need to wait until all refs are set (e.g. when passing a ref down from a parent). | ||
queueMicrotask(()=>{ | ||
if (!didUpdateSize.current) { | ||
didUpdateSize.current = true; | ||
updateSize((0, $f9kpT$flushSync)); | ||
} | ||
}); | ||
}, [ | ||
updateSize | ||
]); | ||
(0, $f9kpT$useEffect)(()=>{ | ||
if (!didUpdateSize.current) { | ||
// If useEffect ran before the above microtask, we are in a synchronous render (e.g. act). | ||
// Update the size here so that you don't need to mock timers in tests. | ||
didUpdateSize.current = true; | ||
updateSize((fn)=>fn()); | ||
if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) { | ||
// React doesn't allow flushSync inside effects, so queue a microtask. | ||
// We also need to wait until all refs are set (e.g. when passing a ref down from a parent). | ||
// If we are in an `act` environment, update immediately without a microtask so you don't need | ||
// to mock timers in tests. In this case, the update is synchronous already. | ||
// IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global. | ||
// https://github.com/reactwg/react-18/discussions/102 | ||
// @ts-ignore | ||
if (typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined') updateSize((fn)=>fn()); | ||
else queueMicrotask(()=>updateSize((0, $f9kpT$flushSync))); | ||
} | ||
}, [ | ||
updateSize | ||
]); | ||
lastContentSize.current = contentSize; | ||
}); | ||
let onResize = (0, $f9kpT$useCallback)(()=>{ | ||
@@ -159,0 +157,0 @@ updateSize((0, $f9kpT$flushSync)); |
{ | ||
"name": "@react-aria/virtualizer", | ||
"version": "3.0.0-nightly-641446f65-240905", | ||
"version": "3.0.0-nightly-8ab4f20de-240913", | ||
"description": "Spectrum UI components in React", | ||
@@ -25,7 +25,7 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@react-aria/i18n": "^3.0.0-nightly-641446f65-240905", | ||
"@react-aria/interactions": "^3.0.0-nightly-641446f65-240905", | ||
"@react-aria/utils": "^3.0.0-nightly-641446f65-240905", | ||
"@react-stately/virtualizer": "^3.0.0-nightly-641446f65-240905", | ||
"@react-types/shared": "^3.0.0-nightly-641446f65-240905", | ||
"@react-aria/i18n": "^3.0.0-nightly-8ab4f20de-240913", | ||
"@react-aria/interactions": "^3.0.0-nightly-8ab4f20de-240913", | ||
"@react-aria/utils": "^3.0.0-nightly-8ab4f20de-240913", | ||
"@react-stately/virtualizer": "^3.0.0-nightly-8ab4f20de-240913", | ||
"@react-types/shared": "^3.0.0-nightly-8ab4f20de-240913", | ||
"@swc/helpers": "^0.5.0" | ||
@@ -32,0 +32,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
187984
2329