Skip to content
Open
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
5 changes: 3 additions & 2 deletions packages/scan/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { type Signal, signal } from '@preact/signals';
import {
type Fiber,
detectReactBuildType,
getRDTHook,
getType,
isInstrumentationActive,
} from 'bippy';

import { type Signal, signal } from '@preact/signals';
import type { ComponentType } from 'preact';
import type { ReactNode } from 'preact/compat';
import type { RenderData } from 'src/core/utils';
Expand All @@ -16,6 +17,7 @@ import { IS_CLIENT } from '~web/utils/constants';
import { readLocalStorage, saveLocalStorage } from '~web/utils/helpers';
import type { Outline } from '~web/utils/outline';
import type { States } from '~web/views/inspector/utils';
import packageJson from '../../package.json';
import type {
ChangeReason,
Render,
Expand All @@ -25,7 +27,6 @@ import type { InternalInteraction } from './monitor/types';
import type { getSession } from './monitor/utils';
import { startTimingTracking } from './notifications/event-tracking';
import { createHighlightCanvas } from './notifications/outline-overlay';
import packageJson from '../../package.json';

let rootContainer: HTMLDivElement | null = null;
let shadowRoot: ShadowRoot | null = null;
Expand Down
3 changes: 2 additions & 1 deletion packages/scan/src/core/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type Signal, signal } from '@preact/signals';
import {
ClassComponentTag,
type Fiber,
Expand All @@ -19,6 +18,8 @@ import {
traverseProps,
traverseRenderedFibers,
} from 'bippy';

import { type Signal, signal } from '@preact/signals';
import { isValidElement } from 'preact';
import { isEqual } from '~core/utils';
import {
Expand Down
1 change: 1 addition & 0 deletions packages/scan/src/core/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getTimings,
isCompositeFiber,
} from 'bippy';

import { type FC, useEffect } from 'react';
import { IS_CLIENT } from '~web/utils/constants';
import {
Expand Down
1 change: 1 addition & 0 deletions packages/scan/src/core/monitor/performance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Fiber, getDisplayName } from 'bippy';

import { getCompositeComponentFromElement } from '~web/views/inspector/utils';
import { Store } from '..';
import type {
Expand Down
1 change: 1 addition & 0 deletions packages/scan/src/core/notifications/performance-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Fiber } from 'bippy';

export const getChildrenFromFiberLL = (fiber: Fiber) => {
const children: Array<Fiber> = [];

Expand Down
1 change: 1 addition & 0 deletions packages/scan/src/core/notifications/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
isHostFiber,
traverseFiber,
} from 'bippy';

import { Store } from '../..';

import {
Expand Down
60 changes: 3 additions & 57 deletions packages/scan/src/core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,9 @@
// @ts-nocheck
import { type Fiber, getType } from 'bippy';

// import type { ComponentType } from 'preact';
import { ReactScanInternals } from '~core/index';
import type { AggregatedRender } from '~web/utils/outline';
import type { AggregatedChange, Render } from './instrumentation';

export const aggregateChanges = (
changes: Array<Change>,
prevAggregatedChange?: AggregatedChange,
) => {
const newChange = {
type: prevAggregatedChange?.type ?? 0,
unstable: prevAggregatedChange?.unstable ?? false,
};
for (const change of changes) {
newChange.type |= change.type;
newChange.unstable = newChange.unstable || (change.unstable ?? false);
}

return newChange;
};

export const joinAggregations = ({
from,
to,
}: {
from: AggregatedRender;
to: AggregatedRender;
}) => {
to.changes.type |= from.changes.type;
to.changes.unstable = to.changes.unstable || from.changes.unstable;
to.aggregatedCount += 1;
to.didCommit = to.didCommit || from.didCommit;
to.forget = to.forget || from.forget;
to.fps = to.fps + from.fps;
to.phase |= from.phase;
to.time = (to.time ?? 0) + (from.time ?? 0);

to.unnecessary = to.unnecessary || from.unnecessary;
};

export const aggregateRender = (
newRender: Render,
prevAggregated: AggregatedRender,
) => {
prevAggregated.changes = aggregateChanges(
newRender.changes,
prevAggregated.changes,
);
prevAggregated.aggregatedCount += 1;
prevAggregated.didCommit = prevAggregated.didCommit || newRender.didCommit;
prevAggregated.forget = prevAggregated.forget || newRender.forget;
prevAggregated.fps = prevAggregated.fps + newRender.fps;
prevAggregated.phase |= newRender.phase;
prevAggregated.time = (prevAggregated.time ?? 0) + (newRender.time ?? 0);

prevAggregated.unnecessary =
prevAggregated.unnecessary || newRender.unnecessary;
};
import type { Render } from './instrumentation';

function descending(a: number, b: number): number {
return b - a;
Expand Down Expand Up @@ -189,7 +135,7 @@ export interface RenderData {
renders: Array<Render>;
displayName: string | null;
type: unknown;
changes?: Array<RenderChange>;
changes?: Array<unknown>;
}

export function isEqual(a: unknown, b: unknown): boolean {
Expand Down
1 change: 1 addition & 0 deletions packages/scan/src/new-outlines/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getNearestHostFibers,
isCompositeFiber,
} from 'bippy';

import { ReactScanInternals, Store, ignoredProps } from '~core/index';
import { createInstrumentation } from '~core/instrumentation';
import { readLocalStorage, removeLocalStorage } from '~web/utils/helpers';
Expand Down
1 change: 1 addition & 0 deletions packages/scan/src/web/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getDisplayName,
hasMemoCache,
} from 'bippy';

import { type ClassValue, clsx } from 'clsx';
import { IS_CLIENT } from './constants';

Expand Down
1 change: 1 addition & 0 deletions packages/scan/src/web/utils/pin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Fiber } from 'bippy';

import { Store } from '~core/index';
import { findComponentDOMNode } from '~web/views/inspector/utils';
import { readLocalStorage } from './helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { signal } from '@preact/signals';
import type { Fiber } from 'bippy';

import { signal } from '@preact/signals';
import type { RenderData } from '~core/instrumentation';

export interface TreeNode {
Expand Down
4 changes: 3 additions & 1 deletion packages/scan/src/web/views/inspector/header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { computed, untracked, useSignalEffect } from '@preact/signals';

import type { Fiber } from 'bippy';

import { computed, untracked, useSignalEffect } from '@preact/signals';
import { useMemo, useRef, useState } from 'preact/hooks';
import { Store } from '~core/index';
import { signalIsSettingsOpen } from '~web/state';
Expand Down
1 change: 1 addition & 0 deletions packages/scan/src/web/views/inspector/overlay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Fiber, getDisplayName } from 'bippy';

import { useEffect, useRef } from 'preact/hooks';
import { ReactScanInternals, Store } from '~core/index';

Expand Down
1 change: 1 addition & 0 deletions packages/scan/src/web/views/inspector/properties.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getDisplayName } from 'bippy';

import {
useCallback,
useEffect,
Expand Down
3 changes: 2 additions & 1 deletion packages/scan/src/web/views/inspector/states.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { signal } from '@preact/signals';
import type { Fiber } from 'bippy';

import { signal } from '@preact/signals';
import type { ComponentType } from 'preact';
import { flashManager } from './flash-overlay';
import { type SectionData, resetTracking } from './timeline/utils';
Expand Down
1 change: 1 addition & 0 deletions packages/scan/src/web/views/inspector/timeline/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isInstrumentationActive } from 'bippy';

import { memo } from 'preact/compat';
import { useCallback, useEffect, useMemo, useRef } from 'preact/hooks';
import { Icon } from '~web/components/icon';
Expand Down
3 changes: 2 additions & 1 deletion packages/scan/src/web/views/inspector/timeline/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type MemoizedState,
SimpleMemoComponentTag,
} from 'bippy';

import { isEqual } from '~core/utils';
import { getChangedPropsDetailed, isPromise } from '../utils';

Expand Down Expand Up @@ -90,7 +91,7 @@ export const trackChange = (
return { hasChanged: false, count: existing.count };
};

export { propsTracker, stateTracker, contextTracker };
export { contextTracker, propsTracker, stateTracker };

export interface SectionData {
current: Array<{ name: string | number; value: unknown }>;
Expand Down
4 changes: 2 additions & 2 deletions packages/scan/src/web/views/inspector/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import {
isHostFiber,
traverseFiber,
} from 'bippy';

import { type PropsChange, ReactScanInternals } from '~core/index';
import { ChangeReason } from '~core/instrumentation';
import { isEqual } from '~core/utils';
import { batchGetBoundingRects } from '~web/utils/outline';
import { globalInspectorState } from '.';
import type { ExtendedReactRenderer } from '../../../types';
import { TIMELINE_MAX_UPDATES } from './states';
import type { MinimalFiberInfo } from './states';
import { TIMELINE_MAX_UPDATES } from './states';
import { getAllFiberContexts, getStateNames } from './timeline/utils';

interface StateItem {
Expand Down Expand Up @@ -145,7 +146,6 @@ export const getParentCompositeFiber = (
return null;
};


const isFiberInTree = (fiber: Fiber, root: Fiber): boolean => {
{
// const root= fiberRootCache.get(fiber) || (fiber.alternate && fiberRootCache.get(fiber.alternate) )
Expand Down