Skip to content

Commit

Permalink
fix react 18 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Feb 7, 2025
1 parent e23fb55 commit 2588fb8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/scan/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const initRootContainer = (): RootContainer => {
'image/svg+xml',
).documentElement;


fragment.appendChild(iconSprite);
fragment.appendChild(cssStyles);
shadowRoot.appendChild(fragment);
Expand Down Expand Up @@ -497,8 +496,9 @@ export const start = () => {

const options = getOptions();

idempotent_createToolbar(!!options.value.showToolbar);
initReactScanInstrumentation();
initReactScanInstrumentation(() =>
idempotent_createToolbar(!!options.value.showToolbar),
);

const isUsedInBrowserExtension = typeof window !== 'undefined';
if (!Store.monitor.value && !isUsedInBrowserExtension) {
Expand Down
8 changes: 7 additions & 1 deletion packages/scan/src/core/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ interface InstrumentationConfig {
onCommitFinish: OnCommitFinishHandler;
onError: OnErrorHandler;
onActive?: OnActiveHandler;
onPostCommitFiberRoot: () => void;
// monitoring does not need to track changes, and it adds overhead to leave it on
trackChanges: boolean;
// allows monitoring to continue tracking renders even if react scan dev mode is disabled
Expand Down Expand Up @@ -419,7 +420,6 @@ export const isRenderUnnecessary = (fiber: Fiber) => {

const TRACK_UNNECESSARY_RENDERS = false;


export const createInstrumentation = (
instanceKey: string,
config: InstrumentationConfig,
Expand Down Expand Up @@ -553,6 +553,12 @@ export const createInstrumentation = (
instance.config.onCommitFinish();
}
},
onPostCommitFiberRoot() {
const allInstances = getAllInstances();
for (const instance of allInstances) {
instance.config.onPostCommitFiberRoot();
}
},
});
}
return instrumentation;
Expand Down
3 changes: 3 additions & 0 deletions packages/scan/src/core/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export const startMonitoring = () => {
onCommitFinish() {
// ReactScanInternals.options.value.onCommitFinish?.();
},
onPostCommitFiberRoot() {
// ...
},
trackChanges: false,
forceAlwaysTrackRenders: true,
});
Expand Down
9 changes: 7 additions & 2 deletions packages/scan/src/new-outlines/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ export const getCanvasEl = () => {

if (IS_OFFSCREEN_CANVAS_WORKER_SUPPORTED) {
try {
const useExtensionWorker = readLocalStorage<boolean>('use-extension-worker');
const useExtensionWorker = readLocalStorage<boolean>(
'use-extension-worker',
);
removeLocalStorage('use-extension-worker');

if (useExtensionWorker) {
Expand Down Expand Up @@ -428,7 +430,7 @@ export const isValidFiber = (fiber: Fiber) => {

return true;
};
export const initReactScanInstrumentation = () => {
export const initReactScanInstrumentation = (setupToolbar: () => void) => {
if (hasStopped()) return;
// todo: don't hardcode string getting weird ref error in iife when using process.env
const instrumentation = createInstrumentation('react-scan-devtools-0.1.0', {
Expand Down Expand Up @@ -480,6 +482,9 @@ export const initReactScanInstrumentation = () => {
onCommitFinish: () => {
ReactScanInternals.options.value.onCommitFinish?.();
},
onPostCommitFiberRoot() {
setupToolbar();
},
trackChanges: false,
});
ReactScanInternals.instrumentation = instrumentation;
Expand Down

0 comments on commit 2588fb8

Please sign in to comment.