question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useGetList on Dashboard breaks when logging out

See original GitHub issue

What you were expecting: Data displayed on a dashboard page and fetched with the useGetList hook should remain consistent and not cause problems when logging out.

What happened instead: When logging out, ids are still filled after re-render, but the data object yields an empty Object. This causes errors if data is rendered like in the useGetList example code in the documentation: https://marmelab.com/react-admin/Actions.html

IDs and data should be consistent!

Steps to reproduce: In case the code sandbox link below shouldn’t be available anymore: I changed the “tutorial” example to load and display data on the dashboard, like so:

import * as React from "react";
import { useGetList } from "react-admin";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import CardHeader from "@material-ui/core/CardHeader";

export default () => {
  const { data, ids, loading, error } = useGetList(
    "posts",
    {
      page: 1,
      perPage: 10
    },
    { field: "published_at", order: "DESC" }
  );
  console.log("######### ids = ", ids, "\n######## data = ", data);
  return (
    <Card>
      <CardHeader title="Welcome to the administration" />
      <CardContent>Lorem ipsum sic dolor amet...</CardContent>
      {!loading && !error && (
        <>
          {ids.map((id) => (
            <p>
              {id}: {data[id].title}
            </p>
          ))}
        </>
      )}
    </Card>
  );
};

When logging out, ids are still present but data becomes an empty object, which breaks the data lookup. The console output looks like this:

######### ids =  
(10) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

######## data =  
{}

Related code: See code sandbox: https://codesandbox.io/s/elegant-volhard-funkp?file=/src/Dashboard.js

Environment

  • React-admin version: ^3.9.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fzaninottocommented, Nov 23, 2020

No, the problem is that the ids and data selectors don’t run together and we can fix it in react-admin. Fix incoming.

0reactions
fzaninottocommented, Nov 23, 2020

No, the bug is in useQueryWithStore. When the data and total selectors return something new, useQueryWithStore runs an effect which then updates the data and total returned by the hook… but at the next tick.

I’m afraid we need a useLayoutEffect here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ra-audit-log documentation | React-Admin Enterprise Edition
This module introduces 3 new components: <Timeline> shows a list of all recent changes in the admin. It's a great component for dashboards....
Read more >
Logged out when you click the 'Reports' or 'Dashboards'
Logged out when you click the 'Reports' or 'Dashboards' ... The user will be logged out because the login needs to be under...
Read more >
8 Ways to Fix “WordPress Keeps Logging Out” Error
It can be frustrating when something goes wrong with your WordPress install (e.g., login issues). Use these easy step-by-step ...
Read more >
Authentication: User logged out after dashboard renders
After authenticating and getting to the backend dashboard ("/Sitefinity"), seconds it loads, it immediately redirects and logs the user out.
Read more >
Tableau Server Logon Guide - User
Tableau Desktop software. 2.3. Tableau server login information. 2.3.1. You must attend training to obtain a log-in to the server. 3.0 Equipment ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found