Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/react-devtools-shared/src/__tests__/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ describe('Store', () => {

await actAsync(() => {
agent.overrideSuspenseMilestone({
rendererID: getRendererID(),
suspendedSet: [
store.getElementIDAtIndex(4),
store.getElementIDAtIndex(8),
Expand Down Expand Up @@ -1010,6 +1011,7 @@ describe('Store', () => {

await actAsync(() => {
agent.overrideSuspenseMilestone({
rendererID: getRendererID(),
suspendedSet: [],
});
});
Expand Down
64 changes: 64 additions & 0 deletions packages/react-devtools-shared/src/backend/DevToolsNativeHost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* 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
*/

import type {HostInstance} from './types';

// Some environments (e.g. React Native / Hermes) don't support the performance API yet.
export const getCurrentTime: () => number =
// $FlowFixMe[method-unbinding]
typeof performance === 'object' && typeof performance.now === 'function'
? () => performance.now()
: () => Date.now();

// Ideally, this should be injected from Reconciler config
export function getPublicInstance(instance: HostInstance): HostInstance {
// Typically the PublicInstance and HostInstance is the same thing but not in Fabric.
// So we need to detect this and use that as the public instance.

// React Native. Modern. Fabric.
if (typeof instance === 'object' && instance !== null) {
if (typeof instance.canonical === 'object' && instance.canonical !== null) {
if (
typeof instance.canonical.publicInstance === 'object' &&
instance.canonical.publicInstance !== null
) {
return instance.canonical.publicInstance;
}
}

// React Native. Legacy. Paper.
if (typeof instance._nativeTag === 'number') {
return instance._nativeTag;
}
}

// React Web. Usually a DOM element.
return instance;
}

export function getNativeTag(instance: HostInstance): number | null {
if (typeof instance !== 'object' || instance === null) {
return null;
}

// Modern. Fabric.
if (
instance.canonical != null &&
typeof instance.canonical.nativeTag === 'number'
) {
return instance.canonical.nativeTag;
}

// Legacy. Paper.
if (typeof instance._nativeTag === 'number') {
return instance._nativeTag;
}

return null;
}
14 changes: 7 additions & 7 deletions packages/react-devtools-shared/src/backend/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ type OverrideSuspenseParams = {
};

type OverrideSuspenseMilestoneParams = {
rendererID: number,
suspendedSet: Array<number>,
};

Expand Down Expand Up @@ -787,15 +788,14 @@ export default class Agent extends EventEmitter<{
};

overrideSuspenseMilestone: OverrideSuspenseMilestoneParams => void = ({
rendererID,
suspendedSet,
}) => {
for (const rendererID in this._rendererInterfaces) {
const renderer = ((this._rendererInterfaces[
(rendererID: any)
]: any): RendererInterface);
if (renderer.supportsTogglingSuspense) {
renderer.overrideSuspenseMilestone(suspendedSet);
}
const renderer = ((this._rendererInterfaces[
(rendererID: any)
]: any): RendererInterface);
if (renderer.supportsTogglingSuspense) {
renderer.overrideSuspenseMilestone(suspendedSet);
}
};

Expand Down
Loading
Loading