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

Various warnings in React 16.13.1 #300

Closed
yunyu opened this issue Mar 20, 2020 · 6 comments · Fixed by #302
Closed

Various warnings in React 16.13.1 #300

yunyu opened this issue Mar 20, 2020 · 6 comments · Fixed by #302
Labels
bug Something isn't working

Comments

@yunyu
Copy link
Contributor

yunyu commented Mar 20, 2020

React version 16.13.1

Concurrent mode no

Describe the bug
React throws warnings when useResource is used anywhere:

Warning: Cannot update a component (`CacheProvider`) while rendering a different component (`PartnerRewards`). To locate the bad setState() call inside `PartnerRewards`, follow the stack trace as described in https://fb.me/setstate-in-render
@yunyu yunyu added the bug Something isn't working label Mar 20, 2020
@ntucker
Copy link
Collaborator

ntucker commented Mar 20, 2020

Thanks for the report!

"To locate the bad setState() call inside PartnerRewards, "

React seems to be suggesting the error is in PartnerRewards. I might be able to assist if the code is shared, but it most certainly is an interaction so hard to say what this is without being able to repro.

@yunyu
Copy link
Contributor Author

yunyu commented Mar 20, 2020

Here is a barebones PartnerRewards that triggers the warning:

class PartnerRewardResource extends CMSResource {
  static urlRoot = `landing-page-partner-rewards/${SORT_BY_RANK}`;

  readonly id!: number;
  readonly company!: string;
  readonly blurb!: string;
  readonly website!: string;
  readonly logo!: Logo;
  readonly rank!: number;

  pk() {
    return this.id.toString();
  }
}

const PartnerRewards: React.FC<{}> = () => {
  const rewardsData = useResource(PartnerRewardResource.listShape(), {});

  return (
    <Box bg="gray4">{JSON.stringify(rewardsData)}</Box>
  );
};

CMSResource is just an extended copy of SimpleResource with a custom fetch - it doesn't touch React. If you have a public API demo to recommend, I may be able to make a repro project. However, this seems to affect every useResource call site.

@ntucker
Copy link
Collaborator

ntucker commented Mar 21, 2020

Thanks, was able to repro, looking into it!

@yunyu
Copy link
Contributor Author

yunyu commented Mar 21, 2020

Appreciate it!

@ntucker
Copy link
Collaborator

ntucker commented Mar 21, 2020

Seems to be the call to fetch, but it seems odd that this would be a problem. I left a comment to get clarity in the react github: facebook/react#18178 (comment)

@ntucker
Copy link
Collaborator

ntucker commented Mar 22, 2020

Appears to be fixed in 4.5.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants