Skip to content
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

[DevTools] fix useDeferredValue to match reconciler change #24742

Merged
merged 5 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 2 additions & 6 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,11 @@ function useTransition(): [
}

function useDeferredValue<T>(value: T): T {
// useDeferredValue() composes multiple hooks internally.
// Advance the current hook index the same number of times
// so that subsequent hooks have the right memoized state.
nextHook(); // State
nextHook(); // Effect
const hook = nextHook();
hookLog.push({
primitive: 'DeferredValue',
stackError: new Error(),
value,
value: hook !== null ? hook.memoizedState : value,
});
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,14 @@ describe('ReactHooksInspectionIntegration', () => {
]);
});

it('should support composite useDeferredValue hook', () => {
it('should support useDeferredValue hook', () => {
function Foo(props) {
React.useDeferredValue('abc', {
timeoutMs: 500,
});
const [state] = React.useState(() => 'hello', []);
return <div>{state}</div>;
const memoizedValue = React.useMemo(() => 1, []);
React.useMemo(() => 2, []);
return <div>{memoizedValue}</div>;
}
const renderer = ReactTestRenderer.create(<Foo />);
const childFiber = renderer.root.findByType(Foo)._currentFiber();
Expand All @@ -590,9 +591,16 @@ describe('ReactHooksInspectionIntegration', () => {
},
{
id: 1,
isStateEditable: true,
name: 'State',
value: 'hello',
isStateEditable: false,
name: 'Memo',
value: 1,
subHooks: [],
},
{
id: 2,
isStateEditable: false,
name: 'Memo',
value: 2,
subHooks: [],
},
]);
Expand Down