Bug: switching tables in the CRUD page leaves blank rows from the previous table
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, react
- Domain
- frontend
Research direction
Start in frontend/crud-react/src/App.jsx, focusing on the row loading effect, reloadRows(), and the table rendering around line 427. Keep fetched rows associated with their table, show a loading state until that table's rows arrive, and check table switching plus add, edit, and delete flows. Done means each table shows only its own rows, late reloads do not replace the selected table's data, and the duplicate key warning is gone.
Written by the indexing model from the issue text.
Description
On the React CRUD page (frontend/crud-react), switching from a table with rows to another table can leave blank rows behind. For example, open audit_log, then switch to app_user. The real users show, followed by dozens of blank rows whose only value is an ID like 2225. The blank rows stay on every table you switch to next (device, vendor, ...) until you open a table with no rows, which clears them. They aren't in the database: they're left on the page by React.
How to reproduce
- Run
.\dev crudand start the React page. - Open
audit_log(it needs several entries written by the same user, so running multiple scans can populate this). - Switch to
app_user: blank rows show under the real users, each withuser_id2225 or 2226. - Switch to
device: the blank rows are still there, now underdevice_id. - Switch to a table with no rows (i.e. alert_setting), then back: the page is correct again.
Why it happens
tableNamechanges the moment a table is picked, butrowschanges only when the fetch inuseEffectreturns. For one render the page draws the new table's columns over the old table's rows.- Each row's React key is
row[table.primary_key](App.jsxline 427). On that render it reads the new table's ID column from the old rows, e.g.user_idon audit-log rows, and many old rows share the same value. - React needs keys to be unique. With duplicate keys it can't match old rows to new ones, so it leaves the extra rows on the page and stops tracking them. Each table switch repeats this, so the leftover rows carry on.
- A table with no rows draws "No rows in ..." instead of the
<table>, which removes the whole table element, leftover rows included. That's why an empty table fixes it. - The same mix-up can happen after adding or deleting a row:
reloadRows()saves whatever it fetched, even if the user has switched tables in the meantime.
Fix (frontend/crud-react/src/App.jsx only)
- Keep the rows together with the table they came from: replace
const [rows, setRows] = useState([])withconst [loaded, setLoaded] = useState({ table: "", rows: [] }). - Show rows only when they belong to the selected table:
const rowsReady = loaded.table === tableName;
const rows = rowsReady ? loaded.rows : []; - The loading effect saves
setLoaded({ table: tableName, rows: rowData }). reloadRows()remembers which table it fetched for and saves{ table: name, rows }. A reload that finishes after a table switch is then ignored.- While the rows for the selected table are loading, show "Loading rows..." instead of "No rows in ...", so a table doesn't briefly claim to be empty.
Why not something else
- Use the row's position in the list as the key. That would hide the leftover rows, but the page would still briefly draw rows under the wrong columns, and React's guidance is to use stable IDs for keys.
- Call
setRows([])at the start of the effect. The effect runs after the render that mixes the tables, so the duplicate keys still happen once.
Done when
- Switching between any tables in any order shows only that table's rows, with no blank leftover rows.
- Switching straight from
audit_logtoapp_usershows only the real users. - "Loading rows..." shows while a table's rows are on the way; "No rows in X." only for a table that's empty.
- Adding, editing and deleting rows still refreshes the list.
- Adding a row and switching tables before the refresh returns leaves the new table's rows on screen.
- No "Encountered two children with the same key" warning in the browser console (F12) while switching tables.
Milestone: M6. Related: #82 (CRUD pagination changes the same file).
- Dominant language
- Python
- Stars
- 1
- Forks
- 1
- Avg merge
- 8h 51m
- Merged PRs (30d)
- 39
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Bearkat-Professionals/Software-Engineering-Project
-
SUBTASK #86: Password hashing (BB-5)Possibly taken @Edgeless6 claimed this 4 days ago. Openbackend Medium Priority subtask
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Bearkat-Professionals/Software-Engineering-Project#87 · 1 assignee ·
Maintainers usually reply within 1 day
-
Enhancement: Regression tests for Validate Input crash fixes (SH-1)Possibly taken @yoshi301 claimed this 3 days ago. Openbackend Low Priority
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Bearkat-Professionals/Software-Engineering-Project#59 · 1 assignee ·
Maintainers usually reply within 1 day
-
backend bug help wanted High Priority
Difficulty 4/5 3-5 days Newbie friendliness 56/100
Bearkat-Professionals/Software-Engineering-Project#97 ·
Maintainers usually reply within 1 day
-
SUBTASK #86: Manage user accounts (admin)Possibly taken @Edgeless6 claimed this 4 days ago. Openbackend Medium Priority subtask
Difficulty 4/5 Over a week Newbie friendliness 20/100
Bearkat-Professionals/Software-Engineering-Project#92 · 1 assignee ·
Maintainers usually reply within 1 day
-
SUBTASK #86: Login screen and signed-in layoutPossibly taken @Solo-Her0 claimed this 4 days ago. Openfrontend Medium Priority subtask
Difficulty 4/5 3-5 days Newbie friendliness 28/100
Bearkat-Professionals/Software-Engineering-Project#91 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in Bearkat-Professionals/Software-Engineering-Project
Similar issues
-
docs size:S
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
strawberry-graphql/strawberry#4794 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
dataforgoodfr/cetolog#21 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
btclib-org/btclib#2932 ·
Maintainers usually reply within 1 day