[DevTools] Allow renaming Host Component props (#35735)

This commit is contained in:
Sebastian "Sebbie" Silbermann
2026-02-09 23:14:46 +01:00
committed by GitHub
parent 4c9d62d2b4
commit 6a939d0b54
2 changed files with 28 additions and 12 deletions

View File

@@ -82,7 +82,12 @@ describe('editing interface', () => {
shallow="initial" shallow="initial"
/> />
, ,
<input ref={inputRef} onChange={jest.fn()} value="initial" /> <input
ref={inputRef}
onChange={jest.fn()}
value="initial"
data-foo="test"
/>
</>, </>,
), ),
); );
@@ -259,6 +264,14 @@ describe('editing interface', () => {
}, },
after: 'initial', after: 'initial',
}); });
renamePath(hostComponentID, ['data-foo'], ['data-bar']);
expect({
foo: inputRef.current.dataset.foo,
bar: inputRef.current.dataset.bar,
}).toEqual({
foo: undefined,
bar: 'test',
});
}); });
// @reactVersion >= 16.9 // @reactVersion >= 16.9

View File

@@ -7874,17 +7874,20 @@ export function attach(
} }
break; break;
case 'props': case 'props':
if (instance === null) { switch (fiber.tag) {
if (typeof overridePropsRenamePath === 'function') { case ClassComponent:
overridePropsRenamePath(fiber, oldPath, newPath); fiber.pendingProps = copyWithRename(
} instance.props,
} else { oldPath,
fiber.pendingProps = copyWithRename( newPath,
instance.props, );
oldPath, instance.forceUpdate();
newPath, break;
); default:
instance.forceUpdate(); if (typeof overridePropsRenamePath === 'function') {
overridePropsRenamePath(fiber, oldPath, newPath);
}
break;
} }
break; break;
case 'state': case 'state':