8000 Warn if you pass a hidden prop to Activity by sebmarkbage · Pull Request #32916 · facebook/react · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Warn if you pass a hidden prop to Activity #32916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
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
16 changes: 16 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
< 8000 td id="diff-d5166797ebbc5b646a49e6a06a049330ca617985d7a6edf3ad1641b43fde1ddfR873" data-line-number="873" class="blob-num blob-num-context js-linkable-line-number js-blob-rnum">
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,22 @@ function updateActivityComponent(
renderLanes: Lanes,
) {
const nextProps: ActivityProps = workInProgress.pendingProps;
if (__DEV__) {
const hiddenProp = (nextProps: any).hidden;
if (hiddenProp !== undefined) {
console.error(
'<Activity> doesn\'t accept a hidden prop. Use mode="hidden" instead.\n' +
'- <Activity %s>\n' +
'+ <Activity %s>',
hiddenProp === true
? 'hidden'
: hiddenProp === false
? 'hidden={false}'
: 'hidden={...}',
hiddenProp ? 'mode="hidden"' : 'mode="visible"',
);
}
}
const nextChildren = nextProps.children;
const nextMode = nextProps.mode;
const mode = workInProgress.mode;
Expand Down
28 changes: 26 additions & 2 deletions packages/react-reconciler/src/__tests__/Activity-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ describe('Activity', () => {

const root = ReactNoop.createRoot();
await act(() => {
root.render(<Activity hidden={false} />);
root.render(<Activity />);
});
assertLog([]);
expect(root).toMatchRenderedOutput(null);
Expand All @@ -741,7 +741,7 @@ describe('Activity', () => {
// Partially render a component
startTransition(() => {
root.render(
<Activity hidden={false}>
<Activity>
<Child />
<Text text="Sibling" />
</Activity>,
Expand Down Expand Up @@ -1480,4 +1480,28 @@ describe('Activity', () => {
assertLog([]);
expect(root).toMatchRenderedOutput(<span prop={2} />);
});

// @gate enableActivity
it('warns if you pass a hidden prop', async () => {
function App() {
return (
// eslint-disable-next-line react/jsx-boolean-value
<Activity hidden>
<div />
</Activity>
);
}

const root = ReactNoop.createRoot();
await act(() => {
root.render(<App show={true} step={1} />);
});
assertConsoleErrorDev([
'<Activity> doesn\'t accept a hidden prop. Use mode="hidden" instead.\n' +
'- <Activity hidden>\n' +
'+ <Activity mode="hidden">\n' +
' in Activity (at **)\n' +
' in App (at **)',
]);
});
});
Loading
0