Skip to content

Commit

Permalink
update devtool info
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWangJustToDo committed Dec 9, 2024
1 parent 9ca7784 commit b0ed1d2
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 56 deletions.
2 changes: 1 addition & 1 deletion packages/myreact-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@
"@my-react/react-reconciler": "^0.3.4"
},
"peerDependencies": {
"@my-react/react": ">=0.3.3"
"@my-react/react": ">=0.3.4"
}
}
2 changes: 1 addition & 1 deletion packages/myreact-jsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
"@my-react/react-shared": "^0.3.4"
},
"peerDependencies": {
"@my-react/react": ">=0.3.3"
"@my-react/react": ">=0.3.4"
}
}
2 changes: 1 addition & 1 deletion packages/myreact-reactivity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@
"@my-react/react-shared": "^0.3.4"
},
"peerDependencies": {
"@my-react/react": ">=0.3.3"
"@my-react/react": ">=0.3.4"
}
}
2 changes: 1 addition & 1 deletion packages/myreact-reconciler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
"@my-react/react-shared": "^0.3.4"
},
"peerDependencies": {
"@my-react/react": ">=0.3.3"
"@my-react/react": ">=0.3.4"
}
}
58 changes: 40 additions & 18 deletions packages/myreact-reconciler/src/renderDispatch/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ type Listeners = {
fiberTrigger: Set<(fiber: MyReactFiberNode, state: UpdateState) => void>;
fiberUnmount: Set<(fiber: MyReactFiberNode) => void>;
fiberHMR?: Set<(fiber: MyReactFiberNode) => void>;
fiberRun?: Set<(fiber: MyReactFiberNode) => void>;
fiberWarn?: Set<(fiber: MyReactFiberNode, ...args: any) => void>;
fiberError?: Set<(fiber: MyReactFiberNode, ...args: any) => void>;
fiberHasChange: Set<(list: ListTree<MyReactFiberNode>) => void>;
performanceWarn?: Set<(fiber: MyReactFiberNode) => void>;
beforeFiberRun?: Set<(fiber: MyReactFiberNode) => void>;
afterFiberRun?: Set<(fiber: MyReactFiberNode) => void>;

instanceInitial: Set<(instance: MyReactComponent, fiber: MyReactFiberNode) => void>;
instanceUpdate: Set<(instance: MyReactComponent, fiber: MyReactFiberNode) => void>;
Expand Down Expand Up @@ -59,7 +60,8 @@ const getInitialValue = (): Listeners => {
fiberHasChange: new Set(),
fiberUnmount: new Set(),
fiberHMR: new Set(),
fiberRun: new Set(),
beforeFiberRun: new Set(),
afterFiberRun: new Set(),
fiberWarn: new Set(),
fiberError: new Set(),
fiberState: new Set(),
Expand Down Expand Up @@ -342,16 +344,16 @@ export class CustomRenderDispatch implements RenderDispatch {
set?.add?.(onceCb);
}

onFiberRun(cb: (_fiber: MyReactFiberNode) => void) {
const set = listenerMap.get(this).fiberRun;
onFiberWarn(cb: (_fiber: MyReactFiberNode, ...args: any) => void) {
const set = listenerMap.get(this).fiberWarn;

set?.add?.(cb);

return () => set?.delete?.(cb);
}

onceFiberRun(cb: (_fiber: MyReactFiberNode) => void) {
const set = listenerMap.get(this).fiberRun;
onceFiberWarn(cb: (_fiber: MyReactFiberNode, ...args: any) => void) {
const set = listenerMap.get(this).fiberWarn;

const onceCb = (_fiber: MyReactFiberNode) => {
cb(_fiber);
Expand All @@ -362,16 +364,16 @@ export class CustomRenderDispatch implements RenderDispatch {
set?.add?.(onceCb);
}

onFiberWarn(cb: (_fiber: MyReactFiberNode, ...args: any) => void) {
const set = listenerMap.get(this).fiberWarn;
onFiberError(cb: (_fiber: MyReactFiberNode, ...args: any) => void) {
const set = listenerMap.get(this).fiberError;

set?.add?.(cb);

return () => set?.delete?.(cb);
}

onceFiberWarn(cb: (_fiber: MyReactFiberNode, ...args: any) => void) {
const set = listenerMap.get(this).fiberWarn;
onceFiberError(cb: (_fiber: MyReactFiberNode, ...args: any) => void) {
const set = listenerMap.get(this).fiberError;

const onceCb = (_fiber: MyReactFiberNode) => {
cb(_fiber);
Expand All @@ -382,16 +384,16 @@ export class CustomRenderDispatch implements RenderDispatch {
set?.add?.(onceCb);
}

onFiberError(cb: (_fiber: MyReactFiberNode, ...args: any) => void) {
const set = listenerMap.get(this).fiberError;
onPerformanceWarn(cb: (_fiber: MyReactFiberNode) => void) {
const set = listenerMap.get(this).performanceWarn;

set?.add?.(cb);

return () => set?.delete?.(cb);
}

onceFiberError(cb: (_fiber: MyReactFiberNode, ...args: any) => void) {
const set = listenerMap.get(this).fiberError;
oncePerformanceWarn(cb: (_fiber: MyReactFiberNode) => void) {
const set = listenerMap.get(this).performanceWarn;

const onceCb = (_fiber: MyReactFiberNode) => {
cb(_fiber);
Expand All @@ -402,16 +404,36 @@ export class CustomRenderDispatch implements RenderDispatch {
set?.add?.(onceCb);
}

onPerformanceWarn(cb: (_fiber: MyReactFiberNode) => void) {
const set = listenerMap.get(this).performanceWarn;
onBeforeFiberRun(cb: (_fiber: MyReactFiberNode) => void) {
const set = listenerMap.get(this).beforeFiberRun;

set?.add?.(cb);

return () => set?.delete?.(cb);
}

oncePerformanceWarn(cb: (_fiber: MyReactFiberNode) => void) {
const set = listenerMap.get(this).performanceWarn;
onceBeforeFiberRun(cb: (_fiber: MyReactFiberNode) => void) {
const set = listenerMap.get(this).beforeFiberRun;

const onceCb = (_fiber: MyReactFiberNode) => {
cb(_fiber);

set?.delete?.(onceCb);
};

set?.add?.(onceCb);
}

onAfterFiberRun(cb: (_fiber: MyReactFiberNode) => void) {
const set = listenerMap.get(this).afterFiberRun;

set?.add?.(cb);

return () => set?.delete?.(cb);
}

onceAfterFiberRun(cb: (_fiber: MyReactFiberNode) => void) {
const set = listenerMap.get(this).afterFiberRun;

const onceCb = (_fiber: MyReactFiberNode) => {
cb(_fiber);
Expand Down
17 changes: 11 additions & 6 deletions packages/myreact-reconciler/src/runtimeGenerate/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,20 @@ export const runtimeNextWork = (fiber: MyReactFiberNode) => {
export const runtimeNextWorkDev = (fiber: MyReactFiberNode) => {
const renderDispatch = currentRenderDispatch.current;

safeCallWithCurrentFiber({
fiber,
action: function safeCallFiberRunListener() {
listenerMap.get(renderDispatch)?.beforeFiberRun?.forEach((cb) => cb(fiber));
},
});

setRefreshTypeMap(fiber);

const typedFiber = fiber as MyReactFiberNodeDev;

const start = Date.now();

const res = runtimeNextWork(fiber);
runtimeNextWork(fiber);

const end = Date.now();

Expand All @@ -201,8 +210,6 @@ export const runtimeNextWorkDev = (fiber: MyReactFiberNode) => {
});
}

const typedFiber = fiber as MyReactFiberNodeDev;

const timeNow = end;

if (enableDebugFiled.current) {
Expand Down Expand Up @@ -234,9 +241,7 @@ export const runtimeNextWorkDev = (fiber: MyReactFiberNode) => {
safeCallWithCurrentFiber({
fiber,
action: function safeCallFiberRunListener() {
listenerMap.get(renderDispatch)?.fiberRun?.forEach((cb) => cb(fiber));
listenerMap.get(renderDispatch)?.afterFiberRun?.forEach((cb) => cb(fiber));
},
});

return res;
};
41 changes: 25 additions & 16 deletions packages/myreact-reconciler/src/runtimeHook/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HOOK_TYPE } from "@my-react/react-shared";
import { initInstance, setContextForInstance, setOwnerForInstance } from "../runtimeGenerate";
import { currentRenderDispatch, getStack, safeCallWithCurrentFiber } from "../share";

import { checkHookValid, isValidHookName, isValidInternalHookName } from "./check";
import { checkHookValid, isValidInternalHookName } from "./check";
import { MyReactHookNode } from "./instance";
import { MyReactSignal } from "./signal";

Expand Down Expand Up @@ -157,26 +157,35 @@ export const createHookNode = ({ type, value, reducer, deps }: RenderHookParams,
try {
const stack = getStack();

const res: NodeJS.CallSite[] = [];
const res = [];

const typedStack = stack.map((i) => {
const line = i.getEnclosingLineNumber();
const column = i.getEnclosingColumnNumber();
const fileName = i.getFileName() || "Unknown";
const functionName = i.getFunctionName() || "Anonymous";
const scriptName = i.getScriptNameOrSourceURL() || "Unknown";
return {
id: `${scriptName}-${fileName}-${functionName}-${line}-${column}`,
name: i.getMethodName() || i.getFunctionName() || "Anonymous",
};
});

while (stack.length > 0 && !isValidInternalHookName(stack[0].getFunctionName())) {
stack.shift();
while (typedStack.length > 0 && !isValidInternalHookName(typedStack[0].name)) {
typedStack.shift();
}

while (stack.length > 0 && isValidHookName(stack[0].getFunctionName())) {
res.push(stack.shift());
while (typedStack.length > 0) {
if (typedStack[0].name === "safeCallForwardRefFunctionalComponent" || typedStack[0].name === "safeCallFunctionalComponent") {
break;
}
res.push(typedStack.shift());
}

typedHook._debugStack = res
.map((i) => {
const line = i.getEnclosingLineNumber();
const column = i.getEnclosingColumnNumber();
const fileName = i.getFileName() || 'Unknown';
const functionName = i.getFunctionName() || "Anonymous";
const scriptName = i.getScriptNameOrSourceURL() || 'Unknown';
return { id: `${scriptName}:${fileName}:${line}:${column}`, name: functionName };
})
.reverse();
// pop current component
res.pop();

typedHook._debugStack = res.reverse();
} catch (e) {
void 0;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/myreact-refresh-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}
},
"peerDependencies": {
"@my-react/react-refresh": ">=0.3.3",
"@my-react/react-refresh": ">=0.3.4",
"webpack": "^4 || ^5"
}
}
2 changes: 1 addition & 1 deletion packages/myreact-refresh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@
"@my-react/react-reconciler": "^0.3.4"
},
"peerDependencies": {
"@my-react/react": ">=0.3.3"
"@my-react/react": ">=0.3.4"
}
}
2 changes: 1 addition & 1 deletion packages/myreact-terminal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@
"@types/wrap-ansi": "^8.1.0"
},
"peerDependencies": {
"@my-react/react": ">=0.3.3"
"@my-react/react": ">=0.3.4"
}
}
2 changes: 1 addition & 1 deletion packages/myreact-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
],
"peerDependencies": {
"@my-react/react-refresh": ">=0.3.3",
"@my-react/react-refresh": ">=0.3.4",
"vite": "^4 || ^5"
},
"dependencies": {
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b0ed1d2

Please sign in to comment.