Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWangJustToDo committed Mar 19, 2024
1 parent d30c1c1 commit e7fdd77
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 25 deletions.
1 change: 1 addition & 0 deletions __tests__/testInput.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<input type="text" value={str} onChange={(e) => setStr(e.target.value)} />
<input value={str} />
<input type='checkbox' defaultChecked='123' />
<textarea defaultValue='111' autoFocus name="" id="" cols="30" rows="10"></textarea>
<label>
Pick a fruit:
<select name="selectedFruit" value='banana'>
Expand Down
11 changes: 10 additions & 1 deletion __tests__/testUnmount.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@
return <div>A {children}</div>
}
const B = ({ children }) => {
const ref = useRef();

useUnmount(() => console.log('b unmount'));

return <div>B {children}</div>
useUnmount(() => {
console.log('dom unmount?', document.body.contains(ref.current))
setTimeout(() => {
console.log('settimeout dom unmount?', document.body.contains(ref.current))
})
})

return <div ref={ref}>B {children}</div>
}
const C = ({ children }) => {
useUnmount(() => console.log('c unmount'));
Expand Down
3 changes: 3 additions & 0 deletions packages/myreact-dom/src/client/api/helper/attr/setAttr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export const setAttribute = (fiber: MyReactFiberNode, el: HTMLElement, name: str
if (el.nodeName === "INPUT" && attrKey === "autofocus") {
requestAnimationFrame(() => el.focus());
}
if (el.nodeName === "TEXTAREA" && attrKey === "autofocus") {
requestAnimationFrame(() => el.focus());
}
}
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/myreact-dom/src/client/renderDispatch/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ if (__DEV__) {
const re = get();

re.then((res) => (parse(res), res)).then((res) => {
unmountFiber(res.__fiber__);
unmountFiber(res.__container__.rootFiber);
res.__container__.isAppMounted = false;
res.__container__.isAppUnmounted = true;
});
Expand Down
6 changes: 3 additions & 3 deletions packages/myreact-dom/src/client/renderPlatform/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export const prepareRenderPlatform = () => {

renderPlatform = currentRenderPlatform.current as DomPlatform;

if (__DEV__ && renderPlatform.isServer) {
console.warn(`[@my-react/react-dom] current environment is server, please use 'renderToString' instead of 'render'`);
}
// if (__DEV__ && renderPlatform.isServer) {
// console.warn(`[@my-react/react-dom] current environment is server, please use 'renderToString' instead of 'render'`);
// }

renderPlatform.isServer = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import type { RenderContainer } from "@my-react-dom-client/mount";
const { currentRenderPlatform } = __my_react_internal__;

export const unmountComponentAtNode = (container: RenderContainer) => {
const fiber = container.__fiber__;

const renderDispatch = container.__container__;

const fiber = renderDispatch.rootFiber;

const renderPlatform = currentRenderPlatform.current as CustomRenderPlatform;

if (!fiber || !renderDispatch || !(fiber instanceof MyReactFiberNode) || !(renderDispatch instanceof ClientDomDispatch)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/myreact-dom/src/server/renderPlatform/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export const prepareRenderPlatform = () => {

renderPlatform = currentRenderPlatform.current as DomPlatform;

if (__DEV__ && !renderPlatform.isServer) {
console.warn(`[@my-react/react-dom] current environment is not server, please use 'render' instead of 'renderToString'`);
}
// if (__DEV__ && !renderPlatform.isServer) {
// console.warn(`[@my-react/react-dom] current environment is not server, please use 'render' instead of 'renderToString'`);
// }

renderPlatform.isServer = true;

Expand Down
23 changes: 8 additions & 15 deletions packages/myreact-dom/src/shared/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@ import { HighLight, debounce } from "@my-react-dom-client/tools";
import { latestNoopRender, legacyNoopRender } from "@my-react-dom-noop/mount/render";
import { PlainElement, ContainerElement, CommentStartElement } from "@my-react-dom-server/api";


import {
enableControlComponent,
enableDOMField,
enableEventSystem,
enableEventTrack,
enableHighlight,
enableHighlightWarn,
isServer,
} from "./env";
import { enableControlComponent, enableDOMField, enableEventSystem, enableEventTrack, enableHighlight, enableHighlightWarn, isServer } from "./env";
import { getFiberWithNativeDom } from "./getFiberWithDom";

import type { LikeJSX } from "@my-react/react";
Expand Down Expand Up @@ -128,7 +119,11 @@ export const prepareDevContainer = (renderDispatch: ClientDomDispatch) => {

if (!isValidElement(element)) return;

const renderDispatch = getCurrentDispatchFromFiber(this) as ClientDomDispatch | ServerDomDispatch | LegacyServerStreamDispatch | LatestServerStreamDispatch;
const renderDispatch = getCurrentDispatchFromFiber(this) as
| ClientDomDispatch
| ServerDomDispatch
| LegacyServerStreamDispatch
| LatestServerStreamDispatch;

const get = async () => {
if (renderDispatch.enableASyncHydrate) {
Expand Down Expand Up @@ -157,7 +152,7 @@ export const prepareDevContainer = (renderDispatch: ClientDomDispatch) => {
const re = get();

re.then((res) => (parse(res), res)).then((res) => {
unmountFiber(res.__fiber__);
unmountFiber(res.__container__.rootFiber);
res.__container__.isAppMounted = false;
res.__container__.isAppUnmounted = true;
});
Expand All @@ -172,11 +167,9 @@ export const prepareDevContainer = (renderDispatch: ClientDomDispatch) => {
* @internal
*/
export const checkRehydrate = (container: Partial<RenderContainer>) => {
const rootFiber = container.__fiber__;

const rootContainer = container.__container__;

if (rootFiber instanceof MyReactFiberNode || rootContainer instanceof ClientDomDispatch) {
if (rootContainer instanceof ClientDomDispatch) {
throw new Error(`[@my-react/react-dom] hydrate error, current container have been hydrated`);
}
};
Expand Down

0 comments on commit e7fdd77

Please sign in to comment.