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
1 change: 1 addition & 0 deletions packages/react-devtools-core/src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ function initialize(socket: WebSocket) {
store = new Store(bridge, {
checkBridgeProtocolCompatibility: true,
supportsNativeInspection: true,
supportsTraceUpdates: true,
});

log('Connected');
Expand Down
2 changes: 2 additions & 0 deletions packages/react-devtools-shared/src/backend/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export default class Agent extends EventEmitter<{
stopInspectingNative: [],
shutdown: [],
traceUpdates: [Set<NativeType>],
drawTraceUpdates: [Array<NativeType>],
disableTraceUpdates: [],
}> {
_bridge: BackendBridge;
_isProfiling: boolean = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type {Data} from './index';
import type {Rect} from '../utils';
import type {NativeType} from '../../types';
import type Agent from '../../agent';

const OUTLINE_COLOR = '#f0f0f0';

Expand All @@ -29,7 +30,17 @@ const COLORS = [

let canvas: HTMLCanvasElement | null = null;

export function draw(nodeToData: Map<NativeType, Data>): void {
export function draw(nodeToData: Map<NativeType, Data>, agent: Agent): void {
if (window.document == null) {
const nodesToDraw = [];
iterateNodes(nodeToData, (_, color, node) => {
nodesToDraw.push({node, color});
});

agent.emit('drawTraceUpdates', nodesToDraw);
return;
}

if (canvas === null) {
initialize();
}
Expand All @@ -40,17 +51,24 @@ export function draw(nodeToData: Map<NativeType, Data>): void {

const context = canvasFlow.getContext('2d');
context.clearRect(0, 0, canvasFlow.width, canvasFlow.height);

nodeToData.forEach(({count, rect}) => {
iterateNodes(nodeToData, (rect, color) => {
if (rect !== null) {
const colorIndex = Math.min(COLORS.length - 1, count - 1);
const color = COLORS[colorIndex];

drawBorder(context, rect, color);
}
});
}

function iterateNodes(
nodeToData: Map<NativeType, Data>,
execute: (rect: Rect | null, color: string, node: NativeType) => void,
) {
nodeToData.forEach(({count, rect}, node) => {
const colorIndex = Math.min(COLORS.length - 1, count - 1);
const color = COLORS[colorIndex];
execute(rect, color, node);
});
}

function drawBorder(
context: CanvasRenderingContext2D,
rect: Rect,
Expand Down Expand Up @@ -79,7 +97,12 @@ function drawBorder(
context.setLineDash([0]);
}

export function destroy(): void {
export function destroy(agent: Agent): void {
if (window.document == null) {
agent.emit('disableTraceUpdates');
return;
}

if (canvas !== null) {
if (canvas.parentNode != null) {
canvas.parentNode.removeChild(canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function toggleEnabled(value: boolean): void {
redrawTimeoutID = null;
}

destroyCanvas();
destroyCanvas(agent);
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@ function prepareToDraw(): void {
}
});

draw(nodeToData);
draw(nodeToData, agent);

if (earliestExpiration !== Number.MAX_VALUE) {
redrawTimeoutID = setTimeout(prepareToDraw, earliestExpiration - now);
Expand Down