fix: validate PerformanceObserver observe options#57030
Conversation
|
Thanks for working on this!
I'm a bit concerned about this one, since this would be against the spec that doesn't define this shouldn't be allowed. Also other vendors don't fail in this case. We shouldn't make existing code break only in RN if we can avoid it. |
|
Btw, the tests should be run via Fantom: |
3fb1452 to
d9f3f54
Compare
|
Good catch, thanks. I removed the Updated commit: d9f3f54 I also tried the Fantom command locally: yarn fantom PerformanceObserver-itestI had to expand the sparse checkout for |
|
@rubennorte has imported this pull request. If you are a Meta employee, you can view this in D107361950. |
Summary:
Harden
PerformanceObserver.observe()option validation so invalid observer configurations fail deterministically before we register a native observer.This fixes a few user-facing gaps in the current implementation:
observe()with no options now throws the expected argument error instead of destructuringundefinedentryTypes/typevalidation messages now match the actual invalid conditionentryTypes: []is rejected instead of silently creating an observer that observes nothingentryTypescombined withbufferedis rejected before native registration, matching the existingdurationThresholdguardThe goal is to prevent malformed performance observer setup from silently succeeding or failing with misleading errors in apps and performance tooling.
Changelog:
[GENERAL] [FIXED] - Validate invalid PerformanceObserver observe option combinations before native registration
Test Plan:
git diff --checknpx --yes prettier@3.6.2 --no-config --single-quote --bracket-spacing=false --trailing-comma=all --arrow-parens=avoid --parser flow --check packages/react-native/src/private/webapis/performance/PerformanceObserver.js packages/react-native/src/private/webapis/performance/__tests__/PerformanceObserver-itest.jsflow-parser@0.316.0Blocked locally:
corepack yarn jest packages/react-native/src/private/webapis/performance/__tests__/PerformanceObserver-itest.js --runInBandcould not run because dependencies are not installed.corepack yarn install --frozen-lockfile --ignore-scriptsfailed resolving unpublished main-version packages such as@react-native/metro-babel-transformer@0.87.0-mainfrom the public registry.