Skip to content

Commit

Permalink
improve highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWangJustToDo committed Nov 14, 2023
1 parent bac908b commit 8ad2cf0
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 147 deletions.
2 changes: 2 additions & 0 deletions packages/myreact-dom/src/client/api/append/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const append = (fiber: MyReactFiberNode, renderDispatch: ClientDomDispatc
parentDom.appendChild(currentDom);
}

renderDispatch.pathToCommitAppend?.(fiber);

fiber.patch = remove(fiber.patch, PATCH_TYPE.__append__);
}
};
2 changes: 2 additions & 0 deletions packages/myreact-dom/src/client/api/update/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const update = (fiber: MyReactFiberNode, renderDispatch: ClientDomDispatc
}
}

renderDispatch.pathToCommitUpdate?.(fiber)

fiber.memoizedProps = fiber.pendingProps;

fiber.patch = remove(fiber.patch, PATCH_TYPE.__update__);
Expand Down
131 changes: 0 additions & 131 deletions packages/myreact-dom/src/client/api/update/highlight.ts

This file was deleted.

13 changes: 1 addition & 12 deletions packages/myreact-dom/src/client/api/update/nativeUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { NODE_TYPE } from "@my-react/react-reconciler";
import { include } from "@my-react/react-shared";

import { enableControlComponent, enableEventSystem, enableHighlight, isEvent, isProperty, isStyle } from "@my-react-dom-shared";
import { enableControlComponent, enableEventSystem, isEvent, isProperty, isStyle } from "@my-react-dom-shared";

import { addEventListener, controlElementTag, removeEventListener, setAttribute, setStyle } from "../helper";

import { mountControl, updateControl } from "./control";
import { HighLight } from "./highlight";
import { getAllKeys } from "./tool";

import type { MyReactFiberNode } from "@my-react/react-reconciler";
Expand Down Expand Up @@ -70,14 +69,4 @@ export const nativeUpdate = (fiber: MyReactFiberNode, renderDispatch: ClientDomD
dom.innerHTML = typedProps.__html as string;
}
}

if (
__DEV__ &&
renderDispatch.isAppMounted &&
!renderDispatch.isHydrateRender &&
!renderDispatch.isServerRender &&
(enableHighlight.current || (window as any).__highlight__)
) {
HighLight.getHighLightInstance().highLight(fiber);
}
};
7 changes: 6 additions & 1 deletion packages/myreact-dom/src/client/mount/hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { initialFiberNode, MyReactFiberNode } from "@my-react/react-reconciler";

import { ClientDomDispatch } from "@my-react-dom-client/renderDispatch";
import { prepareRenderPlatform } from "@my-react-dom-client/renderPlatform";
import { highlightUpdateFiber } from "@my-react-dom-client/tools";
import { checkRehydrate, checkRoot, enableASyncHydrate, prepareDevContainer, startRender, startRenderAsync } from "@my-react-dom-shared";

import { onceLog, onceLogConcurrentMode, onceLogLegacyLifeCycleMode, onceLogPerformanceWarn } from "./render";

import type { RenderContainer } from "./render";
import type { MyReactElement, LikeJSX } from "@my-react/react";
import type { CustomRenderPlatform} from "@my-react/react-reconciler";
import type { CustomRenderPlatform } from "@my-react/react-reconciler";

const { currentRenderPlatform } = __my_react_internal__;

Expand All @@ -24,6 +25,8 @@ const hydrateSync = (element: MyReactElement, container: RenderContainer, cb?: (

renderPlatform.dispatchSet.uniPush(renderDispatch);

__DEV__ && (renderDispatch.pathToCommitUpdate = highlightUpdateFiber);

__DEV__ && checkRoot(fiber);

__DEV__ && prepareDevContainer(renderDispatch);
Expand Down Expand Up @@ -54,6 +57,8 @@ const hydrateAsync = async (element: MyReactElement, container: RenderContainer,

renderPlatform.dispatchSet.uniPush(renderDispatch);

__DEV__ && (renderDispatch.pathToCommitUpdate = highlightUpdateFiber);

__DEV__ && checkRoot(fiber);

__DEV__ && prepareDevContainer(renderDispatch);
Expand Down
4 changes: 3 additions & 1 deletion packages/myreact-dom/src/client/mount/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { include, once, STATE_TYPE } from "@my-react/react-shared";

import { ClientDomDispatch } from "@my-react-dom-client/renderDispatch";
import { prepareRenderPlatform } from "@my-react-dom-client/renderPlatform";
import { unmountComponentAtNode } from "@my-react-dom-client/tools";
import { unmountComponentAtNode, highlightUpdateFiber } from "@my-react-dom-client/tools";
import { checkRoot, prepareDevContainer, startRender } from "@my-react-dom-shared";

import type { LikeJSX } from "@my-react/react";
Expand Down Expand Up @@ -113,6 +113,8 @@ export const render = (element: LikeJSX, _container: Partial<RenderContainer>, c

renderPlatform.dispatchSet.uniPush(renderDispatch);

__DEV__ && (renderDispatch.pathToCommitUpdate = highlightUpdateFiber);

__DEV__ && checkRoot(fiber);

__DEV__ && prepareDevContainer(renderDispatch);
Expand Down
8 changes: 7 additions & 1 deletion packages/myreact-dom/src/client/renderDispatch/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export class ClientDomDispatch extends CustomRenderDispatch {

performanceLogTimeLimit = asyncUpdateTimeLimit.current;

pathToCommitAppend?: (_fiber: MyReactFiberNode) => void;

pathToCommitUpdate?: (_fiber: MyReactFiberNode) => void;

pathToCommitSetRef?: (_fiber: MyReactFiberNode) => void;

commitCreate(_fiber: MyReactFiberNode, _hydrate?: boolean): boolean {
return create(_fiber, this, !!_hydrate);
}
Expand All @@ -59,7 +65,7 @@ export class ClientDomDispatch extends CustomRenderDispatch {
position(_fiber, this);
}
commitSetRef(_fiber: MyReactFiberNode): void {
setRef(_fiber);
setRef(_fiber, this);
}
commitUnsetRef(_fiber: MyReactFiberNode): void {
unsetRef(_fiber);
Expand Down
Loading

0 comments on commit 8ad2cf0

Please sign in to comment.