Skip to content

Commit 6a939d0

Browse files
authored
[DevTools] Allow renaming Host Component props (facebook#35735)
1 parent 4c9d62d commit 6a939d0

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

packages/react-devtools-shared/src/__tests__/editing-test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ describe('editing interface', () => {
8282
shallow="initial"
8383
/>
8484
,
85-
<input ref={inputRef} onChange={jest.fn()} value="initial" />
85+
<input
86+
ref={inputRef}
87+
onChange={jest.fn()}
88+
value="initial"
89+
data-foo="test"
90+
/>
8691
</>,
8792
),
8893
);
@@ -259,6 +264,14 @@ describe('editing interface', () => {
259264
},
260265
after: 'initial',
261266
});
267+
renamePath(hostComponentID, ['data-foo'], ['data-bar']);
268+
expect({
269+
foo: inputRef.current.dataset.foo,
270+
bar: inputRef.current.dataset.bar,
271+
}).toEqual({
272+
foo: undefined,
273+
bar: 'test',
274+
});
262275
});
263276

264277
// @reactVersion >= 16.9

packages/react-devtools-shared/src/backend/fiber/renderer.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7874,17 +7874,20 @@ export function attach(
78747874
}
78757875
break;
78767876
case 'props':
7877-
if (instance === null) {
7878-
if (typeof overridePropsRenamePath === 'function') {
7879-
overridePropsRenamePath(fiber, oldPath, newPath);
7880-
}
7881-
} else {
7882-
fiber.pendingProps = copyWithRename(
7883-
instance.props,
7884-
oldPath,
7885-
newPath,
7886-
);
7887-
instance.forceUpdate();
7877+
switch (fiber.tag) {
7878+
case ClassComponent:
7879+
fiber.pendingProps = copyWithRename(
7880+
instance.props,
7881+
oldPath,
7882+
newPath,
7883+
);
7884+
instance.forceUpdate();
7885+
break;
7886+
default:
7887+
if (typeof overridePropsRenamePath === 'function') {
7888+
overridePropsRenamePath(fiber, oldPath, newPath);
7889+
}
7890+
break;
78887891
}
78897892
break;
78907893
case 'state':

0 commit comments

Comments
 (0)