diff --git a/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js b/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js index 2d723e8cd7ae..f75e7c0375a7 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/IntersectionObserver.js @@ -323,7 +323,7 @@ function normalizeThreshold( return threshold .map(t => normalizeThresholdValue(t, 'threshold')) .map(t => t ?? 0) - .sort(); + .sort((a, b) => a - b); } else if (defaultEmpty) { return []; } else { @@ -359,7 +359,7 @@ function normalizeRootThreshold( const normalizedArr = rootThreshold .map(rt => normalizeThresholdValue(rt, 'rnRootThreshold')) .filter((rt): rt is number => rt != null) - .sort(); + .sort((a, b) => a - b); return normalizedArr.length === 0 ? null : normalizedArr; } diff --git a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js index ac6eda8c618a..db5ad0a407b5 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js @@ -321,6 +321,10 @@ describe('IntersectionObserver', () => { expect( new IntersectionObserver(() => {}, {threshold: [0.5, 0, 1]}).thresholds, ).toEqual([0, 0.5, 1]); + expect( + new IntersectionObserver(() => {}, {threshold: [0.000001, 1e-7]}) + .thresholds, + ).toEqual([1e-7, 0.000001]); // Does NOT deduplicate (browsers don't do it - shrug) expect( @@ -427,6 +431,11 @@ describe('IntersectionObserver', () => { new IntersectionObserver(() => {}, {rnRootThreshold: [0.5, 0, 1]}) .rnRootThresholds, ).toEqual([0, 0.5, 1]); + expect( + new IntersectionObserver(() => {}, { + rnRootThreshold: [0.000001, 1e-7], + }).rnRootThresholds, + ).toEqual([1e-7, 0.000001]); // Does NOT deduplicate (browsers don't do it - shrug) expect(