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

ReferenceField error when logging out #6733

Closed
jeremydrichardson opened this issue Oct 28, 2021 · 5 comments · Fixed by #7105
Closed

ReferenceField error when logging out #6733

jeremydrichardson opened this issue Oct 28, 2021 · 5 comments · Fixed by #7105
Labels

Comments

@jeremydrichardson
Copy link

jeremydrichardson commented Oct 28, 2021

What you were expecting:
Log out of react-admin without errors

What happened instead:
When logging out, errors are thrown to the console.

Uncaught Error: You must declare a <Resource name="users"> in order to use a <ReferenceField reference="users">

The above error occurred in the <ReferenceField> component

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

Steps to reproduce:
Create a component on the dashboard that uses a ReferenceField. Logout and the errors will appear in your console.

I reproduced in CodeSandbox but for some reason it doesn't produce the first one ("Uncaught Error: You must declare a ..."), which the second one is referencing ("the above error occured in the component").

Related code:
I think it may be related to this issue - #5576

https://codesandbox.io/s/react-admin-referencefield-error-ur8wr

Other information:
It's potentially related to the redux issues mentioned in issue 5576 above, the dreadful "Stale Props and "Zombie Children".

What seems to be happening is that upon logout the dashboard is re-rendered due to some state changing. In the process of the dashboard re-rending the redux store is cleared before the ReferenceField is rendered. Then when the ReferenceField attempts to pull its data, the redux store is empty and it can't find the resource.

Environment

  • React-admin version: 3.19.0
  • Last version that did not exhibit the issue (if applicable): ?
  • React version: 17.0.2
  • Browser: Chrome
  • Stack trace (in case of a JS error): (gave the most relevate stack trace with real line numbers...)
Uncaught Error: You must declare a <Resource name="projects"> in order to use a <ReferenceField reference="projects">
    at ReferenceField (ReferenceField.js:86)
    at renderWithHooks (react-dom.development.js:14985)
    at updateFunctionComponent (react-dom.development.js:17356)
    at beginWork (react-dom.development.js:19063)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
    at invokeGuardedCallback (react-dom.development.js:4056)
    at beginWork$1 (react-dom.development.js:23964)
    at performUnitOfWork (react-dom.development.js:22776)
    at workLoopSync (react-dom.development.js:22707)
    at renderRootSync (react-dom.development.js:22670)
    at performSyncWorkOnRoot (react-dom.development.js:22293)
    at react-dom.development.js:11327
    at unstable_runWithPriority (scheduler.development.js:468)
    at runWithPriority$1 (react-dom.development.js:11276)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11322)
    at flushSyncCallbackQueue (react-dom.development.js:11309)
    at batchedUpdates$1 (react-dom.development.js:22387)
    at Object.notify (Subscription.js:15)
    at Object.notifyNestedSubs (Subscription.js:85)
    at handleChangeWrapper (Subscription.js:90)
    at Object.dispatch (redux.js:297)
    at dispatch (<anonymous>:3856:17)
    at middleware.js:26
    at Object.dispatch (redux-saga-core.esm.js:1410)
    at dispatch (<anonymous>:14608:80)
    at useLogout.js:45
@djhi
Copy link
Contributor

djhi commented Oct 29, 2021

The codesandbox you linked is empty. Can you please fork & tweak the simple example to show the issue? Thanks!

@jeremydrichardson
Copy link
Author

The codesandbox you linked is empty. Can you please fork & tweak the simple example to show the issue? Thanks!

Sorry, somehow I pasted the wrong link. It's fixed in the main issue body and here is the link for quick reference as well.

CodeSandbox example: https://codesandbox.io/s/react-admin-referencefield-error-ur8wr

@jeremydrichardson
Copy link
Author

I would add one more thing I noticed in the CodeSandbox version that I'm not experiencing locally but might help.

The first time the CodeSandbox boots up, when you login it will display the error Uncaught Error: You must declare a <Resource name="users"> in order to use a <ReferenceField reference="users">

As I mentioned in the initial post, I get that error locally but only on logout. I thinking perhaps the differences are due to the authProvider in the CodeSandbox is a simulation and returns far faster than my Amplify authProvider I'm using in our project. Could indicate a race condition of some kind.

Either way I think it's related to the same issue and hopefully I can help find a fix for it.

@WiXSL
Copy link
Contributor

WiXSL commented Nov 22, 2021

Reproduced. Thanks

@neutron92
Copy link

Allo i have the same error
image
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants