Skip to content

Commit

Permalink
fix error for attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWangJustToDo committed Feb 20, 2024
1 parent 3bb177b commit 091489f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions packages/myreact-dom/src/client/api/update/hydrateUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const domPropsHydrate = (fiber: MyReactFiberNode, isSVG: boolean, key: string, v
if (value !== null && value !== undefined) {
if (key === "className") {
if (isSVG) {
const has = dom.hasAttribute('class');
const has = dom.hasAttribute("class");
if (!has) {
if (enableHydrateWarn.current) {
log(fiber, "warn", `hydrate warning, dom '${key}' not match from server. no have this attr from server, client: ${value}`);
Expand All @@ -66,7 +66,7 @@ const domPropsHydrate = (fiber: MyReactFiberNode, isSVG: boolean, key: string, v
if (enableHydrateWarn.current) {
log(fiber, "warn", `hydrate warning, dom '${key}' not match from server. server: ${dom[key]}, client: ${value}`);
}
dom[key] = (value as string);
dom[key] = value as string;
}
}
} else if (isSVG && key.charCodeAt(0) === X_CHAR) {
Expand Down Expand Up @@ -193,7 +193,11 @@ export const hydrateUpdate = (fiber: MyReactFiberNode, renderDispatch: ClientDom
} else if (isStyle(key)) {
domStyleHydrate(fiber, key, (props[key] as Record<string, unknown>) || {});
} else if (isProperty(key)) {
domPropsHydrate(fiber, isSVG, key, props[key]);
try {
domPropsHydrate(fiber, isSVG, key, props[key]);
} catch {
void 0;
}
}
});

Expand Down
6 changes: 5 additions & 1 deletion packages/myreact-dom/src/client/api/update/nativeUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export const nativeUpdate = (fiber: MyReactFiberNode, renderDispatch: ClientDomD
.filter((key) => !Object.is(typedOldValue[key], typedNewValue[key]))
.forEach((key) => setStyle(fiber, dom, key, typedNewValue[key] as string | number | null | undefined));
} else if (isProperty(key)) {
setAttribute(fiber, dom, key, isSVG, newValue);
try {
setAttribute(fiber, dom, key, isSVG, newValue);
} catch {
void 0;
}
}
}
});
Expand Down

0 comments on commit 091489f

Please sign in to comment.