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

Bug: useDeferredValue not respecting timeoutMs parameter #19998

Closed
lourd opened this issue Oct 11, 2020 · 3 comments
Closed

Bug: useDeferredValue not respecting timeoutMs parameter #19998

lourd opened this issue Oct 11, 2020 · 3 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@lourd
Copy link

lourd commented Oct 11, 2020

React version: 0.0.0-experimental-4ead6b530
ReactDOM version: 0.0.0-experimental-4ead6b530

Steps To Reproduce

I'm not sure if this is a bug or a misunderstanding. As part of learning Suspense and using it in a project, I was puzzled by the behavior of useDeferredValue. When using it, my component seemed to use the deferred value until the new UI state was unsuspended/done rendering, regardless of the timeoutMs parameter.

I forked the Code Sandbox linked from the Concurrent UI Patterns to try and distill the problem. First, when using useDeferredValue in the child component, the timeoutMs does have the expected effect, when using either version of React. But then, when I moved the use of useDeferredValue higher to the App component to match how I was using it, the behavior differed. When using 0.0.0-experimental-5faf377df, it does have an effect. But in the most recent react@experimental, 0.0.0-experimental-4ead6b530, it no longer has an effect.

function App() {
  const [resource, setResource] = useState(initialResource);
  const deferredResource = useDeferredValue(resource, {
    timeoutMs: 42 // Doesn't appear to be making a difference in the latest React
  });
  const isPending = deferredResource !== resource;
  return (
    <>
      <button
        disabled={isPending}
        onClick={() => {
          // startTransition(() => {
          const nextUserId = getNextId(resource.userId);
          setResource(fetchProfileData(nextUserId));
          // });
        }}
      >
        Next
      </button>
      {isPending ? " Loading..." : null}
      <ProfilePage
        resource={deferredResource}
        isStale={deferredResource !== resource}
      />
    </>
  );
}

function ProfilePage({ resource, isStale }) {
  return (
    <Suspense fallback={<h1>Loading profile...</h1>}>
      <ProfileDetails resource={resource} />
      <Suspense fallback={<h1>Loading posts...</h1>}>
        <ProfileTimeline resource={resource} isStale={isStale} />
      </Suspense>
    </Suspense>
  );
}
@lourd lourd added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Oct 11, 2020
@threepointone
Copy link
Contributor

This is by design #19703 #19704

@gaearon
Copy link
Collaborator

gaearon commented Oct 15, 2020

Yeah the docs unfortunately are getting outdated. We’ll need to do a cleanup pass.

@lourd
Copy link
Author

lourd commented Oct 15, 2020

Gotcha, thanks for the links and clarification!

@lourd lourd closed this as completed Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

3 participants