You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary
I am running into an issue where the graphql data coming out of Hasura (Postgres in my case) breaks React-Admin list pages when using the <InfiniteList> tag. Infinite list is a infinite scroll version of the standard list. It fills the screen with data, so if the window is 15 rows high, it will load at least 20 rows initially.
Error:
Warning: Encountered two children with the same key, 13. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
Environment
"react-admin": "^4.16.5",
"ra-data-hasura": "^0.6.0",
Tag:
Background
React requires a unique key for each row rendered on the screen. This is typically just the primary key, or in our case an incrementing number column. Collisions to this ID cause rendering issues and an error emitted on the screen.
Repro
Use react-admin with ra-data-hasura.
Create a resource in react-admin to target a table in hasura.
Customize that resource with an InfiniteList element. Display all the columns, such as id, name and count (or some number).
Ensure the hasura table for the resource has:
at least 20-40 rows
at least one number column
15 rows that have the same numerical value 0 (just so they show up at the top)
Run this in the browser, and sort on the numerical column.
Expected
A screen worth of rows load (make sure your screen is taller than 10 rows so the second page of data is loaded).
Actual
Some rows load, errors are displayed in the console. When changing sort order further, some rows are stuck on the screen.
Error:
Warning: Encountered two children with the same key, 13. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
Explanation
InfiniteList loads records 10 rows at a time. So the first 10, sorted by count, with offset 0. And the second 10 , sorted by count, with offset 10. Which look something like this when executed: SELECT * FROM users ORDER BY count LIMIT 10 OFFSET 0; SELECT * FROM users ORDER BY count LIMIT 10 OFFSET 10;
The sort on a column with multiple identical values is non-deterministic in SQL. That is to say, if there are 15 entries with count = 0, the order of the 15 entries may be different each time its sorted by count. For the first SELECT the table is sorted by count, and 10 rows returned. Then the table is sorted again for the second SELECT, and the rows 10-19 returned.
Example. Note the overlapping IDs. That breaks react admin.
Response for SELECT * FROM users ORDER BY count LIMIT 10 OFFSET 0; ID Name Count 1 One 0 12 One 0 13 One 0 22 One 0 3 One 0 6 One 0 9 One 0 11 One 0 15 One 0 31 One 0
Response for SELECT * FROM users ORDER BY count LIMIT 10 OFFSET 10; ID Name Count 4 One 0 32 One 0 33 One 0 34 One 0 1 One 0 8 One 0 13 One 0 6 One 0 4 One 3 30 One 8
Solution
Always append the table's primary key column to ORDER BY (see , id below): SELECT * FROM users ORDER BY count, id LIMIT 10 OFFSET 0;
This change I think makes the most sense in the data provider so it can be forgotten about by everyone else using this data provider in the future.
The text was updated successfully, but these errors were encountered:
Summary
I am running into an issue where the graphql data coming out of Hasura (Postgres in my case) breaks React-Admin list pages when using the
<InfiniteList>
tag. Infinite list is a infinite scroll version of the standard list. It fills the screen with data, so if the window is 15 rows high, it will load at least 20 rows initially.Error:
Environment
Background
React requires a unique key for each row rendered on the screen. This is typically just the primary key, or in our case an incrementing number column. Collisions to this ID cause rendering issues and an error emitted on the screen.
Repro
Expected
A screen worth of rows load (make sure your screen is taller than 10 rows so the second page of data is loaded).
Actual
Some rows load, errors are displayed in the console. When changing sort order further, some rows are stuck on the screen.
Error:
Explanation
InfiniteList loads records 10 rows at a time. So the first 10, sorted by count, with offset 0. And the second 10 , sorted by count, with offset 10. Which look something like this when executed:
SELECT * FROM users ORDER BY count LIMIT 10 OFFSET 0;
SELECT * FROM users ORDER BY count LIMIT 10 OFFSET 10;
The sort on a column with multiple identical values is non-deterministic in SQL. That is to say, if there are 15 entries with count = 0, the order of the 15 entries may be different each time its sorted by count. For the first SELECT the table is sorted by count, and 10 rows returned. Then the table is sorted again for the second SELECT, and the rows 10-19 returned.
Example. Note the overlapping IDs. That breaks react admin.
Response for
SELECT * FROM users ORDER BY count LIMIT 10 OFFSET 0;
ID Name Count
1 One 0
12 One 0
13 One 0
22 One 0
3 One 0
6 One 0
9 One 0
11 One 0
15 One 0
31 One 0
Response for
SELECT * FROM users ORDER BY count LIMIT 10 OFFSET 10;
ID Name Count
4 One 0
32 One 0
33 One 0
34 One 0
1 One 0
8 One 0
13 One 0
6 One 0
4 One 3
30 One 8
Solution
Always append the table's primary key column to ORDER BY (see
, id
below):SELECT * FROM users ORDER BY count, id LIMIT 10 OFFSET 0;
This change I think makes the most sense in the data provider so it can be forgotten about by everyone else using this data provider in the future.
The text was updated successfully, but these errors were encountered: