Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

fix: 修复 style props 变更的错误异常 #1446

Merged
merged 2 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ describe('diffProperties', () => {
expect(!!diffProperties({ autoFocus: true }, {})).toBeTruthy();
expect(!!diffProperties({ children: '1' }, {})).toBeTruthy();

const lastProps = { style: { width: 1 } };
const nextProps = { style: { width: 2, height: 1 } };
diffProperties(lastProps, nextProps);
diffProperties(nextProps, { style: { width: 3, height: 1 } });
expect(nextProps).toMatchObject({ style: { width: 2, height: 1 } });
expect(lastProps).toMatchObject({ style: { width: 1 } });
const update = () => {
nextProps.style = { width: 3, height: 1 };
};
expect(update()).toBeUndefined();
expect(nextProps).toMatchObject({ style: { width: 3, height: 1 } });

const sameFn = () => void 0;
expect(!!diffProperties({ a: sameFn }, { a: sameFn })).toBeFalsy();
expect(!!diffProperties({ a: () => void 0 }, { a: () => void 0 })).toBeTruthy();
Expand Down
2 changes: 1 addition & 1 deletion packages/remax-runtime/src/hostConfig/diffProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function diffProperties(
for (const styleKey in styleUpdates) {
const styleValue = styleUpdates[styleKey];
if (styleValue) {
updatePayload.push(styleKey, Object.assign(lastProps[styleKey] || {}, styleValue));
updatePayload.push(styleKey, Object.assign({}, lastProps[styleKey], styleValue));
}
}

Expand Down