mirror of
https://github.com/react/react-native.git
synced 2026-09-29 16:58:04 +08:00
Strip all "bom" types that are actually not defined in RN (#49730)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49730 Changelog: [internal] This removes all the types from "bom" that are actually not implemented in RN. For now, we're just stripping whole interfaces and not looking into specific methods/properties in interfaces that we do implement but not 100%. `Performance`, `PerformanceObserver`, `MutationObserver` and `IntersectionObserver` are implemented but not stable yet, so they aren't exposed as globals in the types. Reviewed By: huntie Differential Revision: D70329185 fbshipit-source-id: 63bac619e100ca66b41df071df80dfa73d0f9651
This commit is contained in:
committed by
Facebook GitHub Bot
parent
52713eeff3
commit
84a1211773
@@ -152,6 +152,7 @@ if (__DEV__) {
|
||||
// Read the optional global variable for backward compatibility.
|
||||
// It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0.
|
||||
const port =
|
||||
// $FlowFixMe[prop-missing]
|
||||
// $FlowFixMe[incompatible-use]
|
||||
window.__REACT_DEVTOOLS_PORT__ != null
|
||||
? window.__REACT_DEVTOOLS_PORT__
|
||||
|
||||
@@ -14,6 +14,7 @@ import type {
|
||||
EventCallback,
|
||||
EventListener,
|
||||
} from '../../src/private/webapis/dom/events/EventTarget';
|
||||
import type Performance from '../../src/private/webapis/performance/Performance';
|
||||
import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger';
|
||||
|
||||
import Event from '../../src/private/webapis/dom/events/Event';
|
||||
@@ -33,6 +34,8 @@ const RCTNetworking = require('./RCTNetworking').default;
|
||||
const base64 = require('base64-js');
|
||||
const invariant = require('invariant');
|
||||
|
||||
declare var performance: Performance;
|
||||
|
||||
const DEBUG_NETWORK_SEND_DELAY: false = false; // Set to a number of milliseconds when debugging
|
||||
const LABEL_FOR_MISSING_URL_FOR_PROFILING = 'Unknown URL';
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import type Performance from '../../src/private/webapis/performance/Performance';
|
||||
import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger';
|
||||
|
||||
import {type EventSubscription} from '../vendor/emitter/EventEmitter';
|
||||
@@ -22,6 +23,8 @@ const RCTNetworking = require('./RCTNetworking').default;
|
||||
const base64 = require('base64-js');
|
||||
const invariant = require('invariant');
|
||||
|
||||
declare var performance: Performance;
|
||||
|
||||
const DEBUG_NETWORK_SEND_DELAY: false = false; // Set to a number of milliseconds when debugging
|
||||
const LABEL_FOR_MISSING_URL_FOR_PROFILING = 'Unknown URL';
|
||||
|
||||
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict
|
||||
* @nolint
|
||||
* @format
|
||||
*/
|
||||
|
||||
declare class Position {
|
||||
coords: Coordinates;
|
||||
timestamp: number;
|
||||
mocked: boolean;
|
||||
}
|
||||
Vendored
+2
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
import type MutationObserverType from '../MutationObserver';
|
||||
import type MutationRecordType from '../MutationRecord';
|
||||
|
||||
import View from '../../../../../Libraries/Components/View/View';
|
||||
import setUpMutationObserver from '../../../setup/setUpMutationObserver';
|
||||
@@ -22,6 +23,7 @@ import * as React from 'react';
|
||||
import '../../../../../Libraries/Core/InitializeCore.js';
|
||||
|
||||
declare const MutationObserver: Class<MutationObserverType>;
|
||||
declare const MutationRecord: Class<MutationRecordType>;
|
||||
|
||||
setUpMutationObserver();
|
||||
|
||||
|
||||
+5
-1
@@ -10,10 +10,14 @@
|
||||
* @fantom_flags enableLongTaskAPI:true
|
||||
*/
|
||||
|
||||
import type {PerformanceObserverCallbackOptions} from '../PerformanceObserver';
|
||||
import type {
|
||||
PerformanceObserverCallbackOptions,
|
||||
PerformanceObserverEntryList,
|
||||
} from '../PerformanceObserver';
|
||||
|
||||
import setUpPerformanceObserver from '../../../setup/setUpPerformanceObserver';
|
||||
import {PerformanceLongTaskTiming} from '../LongTasks';
|
||||
import {PerformanceObserver} from '../PerformanceObserver';
|
||||
import Fantom from '@react-native/fantom';
|
||||
import nullthrows from 'nullthrows';
|
||||
|
||||
|
||||
Vendored
+10
-3
@@ -12,8 +12,12 @@
|
||||
|
||||
import '../../../../../Libraries/Core/InitializeCore.js';
|
||||
|
||||
import type Performance from '../Performance';
|
||||
|
||||
import Fantom from '@react-native/fantom';
|
||||
|
||||
declare var performance: Performance;
|
||||
|
||||
const clearMarksAndMeasures = () => {
|
||||
performance.clearMarks();
|
||||
performance.clearMeasures();
|
||||
@@ -76,7 +80,9 @@ Fantom.unstable_benchmark
|
||||
performance.clearMarks('mark');
|
||||
},
|
||||
{
|
||||
beforeEach: () => performance.mark('mark'),
|
||||
beforeEach: () => {
|
||||
performance.mark('mark');
|
||||
},
|
||||
},
|
||||
)
|
||||
.test(
|
||||
@@ -85,11 +91,12 @@ Fantom.unstable_benchmark
|
||||
performance.clearMeasures('measure');
|
||||
},
|
||||
{
|
||||
beforeEach: () =>
|
||||
beforeEach: () => {
|
||||
performance.measure('measure', {
|
||||
start: 100,
|
||||
end: 300,
|
||||
}),
|
||||
});
|
||||
},
|
||||
},
|
||||
)
|
||||
.test('mark + clearMarks', () => {
|
||||
|
||||
+5
-2
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line lint/sort-imports
|
||||
import type Performance from '../Performance';
|
||||
import {performanceEntryTypeToRaw} from '../internals/RawPerformanceEntry';
|
||||
import {reportEntry} from '../specs/__mocks__/NativePerformanceMock';
|
||||
|
||||
@@ -17,6 +18,8 @@ jest.mock('../specs/NativePerformance', () =>
|
||||
require('../specs/__mocks__/NativePerformanceMock'),
|
||||
);
|
||||
|
||||
declare var performance: Performance;
|
||||
|
||||
const NativePerformanceMock =
|
||||
require('../specs/__mocks__/NativePerformanceMock').default;
|
||||
|
||||
@@ -24,9 +27,9 @@ describe('Performance', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
|
||||
const Performance = require('../Performance').default;
|
||||
const PerformanceClass = require('../Performance').default;
|
||||
// $FlowExpectedError[cannot-write]
|
||||
global.performance = new Performance();
|
||||
global.performance = new PerformanceClass();
|
||||
});
|
||||
|
||||
it('reports marks and measures', () => {
|
||||
|
||||
Vendored
+8
-2
@@ -9,20 +9,26 @@
|
||||
* @oncall react_native
|
||||
*/
|
||||
|
||||
import type Performance from '../Performance';
|
||||
import type {PerformanceEntryList} from '../PerformanceEntry';
|
||||
|
||||
jest.mock(
|
||||
'../specs/NativePerformance',
|
||||
() => require('../specs/__mocks__/NativePerformanceMock').default,
|
||||
);
|
||||
|
||||
declare var performance: Performance;
|
||||
|
||||
describe('PerformanceObserver', () => {
|
||||
let PerformanceObserver;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
|
||||
const Performance = require('../Performance').default;
|
||||
// $FlowExpectedError[cannot-write]
|
||||
global.performance = new Performance();
|
||||
global.PerformanceObserver =
|
||||
require('../PerformanceObserver').PerformanceObserver;
|
||||
PerformanceObserver = require('../PerformanceObserver').PerformanceObserver;
|
||||
});
|
||||
|
||||
it('prevents durationThreshold to be used together with entryTypes', async () => {
|
||||
|
||||
+5
@@ -10,8 +10,11 @@
|
||||
* @fantom_flags enableLongTaskAPI:true
|
||||
*/
|
||||
|
||||
import type Performance from '../Performance';
|
||||
|
||||
import setUpPerformanceObserver from '../../../setup/setUpPerformanceObserver';
|
||||
import ensureInstance from '../../../utilities/ensureInstance';
|
||||
import {PerformanceObserver} from '../PerformanceObserver';
|
||||
import {PerformanceMark} from '../UserTiming';
|
||||
import Fantom from '@react-native/fantom';
|
||||
|
||||
@@ -19,6 +22,8 @@ import '../../../../../Libraries/Core/InitializeCore.js';
|
||||
|
||||
setUpPerformanceObserver();
|
||||
|
||||
declare var performance: Performance;
|
||||
|
||||
describe('User Timing API', () => {
|
||||
describe('performance.mark()', () => {
|
||||
it('reports marks to observers', () => {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
* @format
|
||||
* @oncall flow
|
||||
*/
|
||||
@@ -109,12 +110,6 @@ declare class DataTransferItem {
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry
|
||||
*/
|
||||
webkitGetAsEntry(): void | (() => any);
|
||||
/*
|
||||
* Not supported in all browsers
|
||||
* For up to date compatibility information, please visit
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/getAsFileSystemHandle
|
||||
*/
|
||||
getAsFileSystemHandle?: () => Promise<?FileSystemHandle>;
|
||||
}
|
||||
|
||||
/* DOM */
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
import type IntersectionObserverType from 'react-native/src/private/webapis/intersectionobserver/IntersectionObserver';
|
||||
|
||||
import {RNTesterThemeContext} from '../../components/RNTesterTheme';
|
||||
import * as React from 'react';
|
||||
import {
|
||||
@@ -19,6 +21,8 @@ import {
|
||||
} from 'react';
|
||||
import {Button, ScrollView, StyleSheet, Text, View} from 'react-native';
|
||||
|
||||
declare var IntersectionObserver: Class<IntersectionObserverType>;
|
||||
|
||||
export const name = 'IntersectionObserver Benchmark';
|
||||
export const title = name;
|
||||
export const description =
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
import type IntersectionObserverType from 'react-native/src/private/webapis/intersectionobserver/IntersectionObserver';
|
||||
|
||||
import {RNTesterThemeContext} from '../../components/RNTesterTheme';
|
||||
import * as React from 'react';
|
||||
import {
|
||||
@@ -19,6 +21,8 @@ import {
|
||||
} from 'react';
|
||||
import {Button, ScrollView, StyleSheet, Text, View} from 'react-native';
|
||||
|
||||
declare var IntersectionObserver: Class<IntersectionObserverType>;
|
||||
|
||||
export const name = 'IntersectionObserver MDN Example';
|
||||
export const title = name;
|
||||
export const description =
|
||||
|
||||
+3
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
|
||||
import type IntersectionObserverType from 'react-native/src/private/webapis/intersectionobserver/IntersectionObserver';
|
||||
|
||||
import {RNTesterThemeContext} from '../../components/RNTesterTheme';
|
||||
import * as React from 'react';
|
||||
@@ -21,6 +22,8 @@ import {
|
||||
} from 'react';
|
||||
import {Button, ScrollView, StyleSheet, Text, View} from 'react-native';
|
||||
|
||||
declare const IntersectionObserver: Class<IntersectionObserverType>;
|
||||
|
||||
export const name = 'IntersectionObserver Root Threshold';
|
||||
export const title = name;
|
||||
export const description =
|
||||
|
||||
@@ -22,6 +22,7 @@ export const description = 'API to detect mutations in React Native nodes.';
|
||||
export const showIndividualExamples = true;
|
||||
export const examples: Array<RNTesterModuleExample> = [MutationObserverExample];
|
||||
|
||||
// $FlowExpectedError[cannot-resolve-name]
|
||||
if (typeof IntersectionObserver !== 'undefined') {
|
||||
examples.push(VisualCompletionExample);
|
||||
}
|
||||
|
||||
@@ -214,6 +214,7 @@ const APIs: Array<RNTesterModuleInfo> = ([
|
||||
.default,
|
||||
},
|
||||
// Only show the link for the example if the API is available.
|
||||
// $FlowExpectedError[cannot-resolve-name]
|
||||
typeof IntersectionObserver === 'function'
|
||||
? {
|
||||
key: 'IntersectionObserver',
|
||||
@@ -250,6 +251,7 @@ const APIs: Array<RNTesterModuleInfo> = ([
|
||||
category: 'UI',
|
||||
module: require('../examples/Layout/LayoutExample'),
|
||||
},
|
||||
// $FlowExpectedError[cannot-resolve-name]
|
||||
typeof MutationObserver === 'function'
|
||||
? {
|
||||
key: 'MutationObserver',
|
||||
|
||||
@@ -223,6 +223,7 @@ const APIs: Array<RNTesterModuleInfo> = ([
|
||||
.default,
|
||||
},
|
||||
// Only show the link for the example if the API is available.
|
||||
// $FlowExpectedError[cannot-resolve-name]
|
||||
typeof IntersectionObserver === 'function'
|
||||
? {
|
||||
key: 'IntersectionObserver',
|
||||
@@ -250,6 +251,7 @@ const APIs: Array<RNTesterModuleInfo> = ([
|
||||
key: 'LinkingExample',
|
||||
module: require('../examples/Linking/LinkingExample'),
|
||||
},
|
||||
// $FlowExpectedError[cannot-resolve-name]
|
||||
typeof MutationObserver === 'function'
|
||||
? {
|
||||
key: 'MutationObserver',
|
||||
|
||||
Reference in New Issue
Block a user