Debugging means finding where the story changes
Suppose the page says "No resources found," but the JSON file contains three resources. Do not change several functions at once. Follow one resource from the file to the screen.
Ask the same simple question at every step: is my resource still here, and does it still have the expected value?
1. requested file
|
v
2. HTTP response
|
v
3. parsed JavaScript value
|
v
4. state.items
|
v
5. visibleItems after filtering
|
v
6. value received by render
|
v
7. DOM element on the page
The first incorrect step tells you where to investigate. If the Network panel shows three resources but state.items is empty, the problem happened between parsing and the state assignment.
A slow method is faster than guessing
- Reproduce the problem with the same action.
- Write the expected result in one sentence.
- Start at the data source.
- Inspect one boundary at a time.
- Stop at the first unexpected value.
- Correct one cause.
- Repeat the original action.
Example: the list appears before the data
async function init() {
render();
state.items = await fetchResources();
}
Trace it:
render()reads the initial empty array.- It displays an empty list.
- The data arrives and enters state.
- No render runs after the assignment.
- The screen remains old even though state is correct.
The smallest correction is to render after the state changes:
async function init() {
state.items = await fetchResources();
render();
}
Explain three more bugs
For each bug, say what the user sees and which step of the flow is wrong.
- Filtering assigns its result back to
state.items. Returning toallcannot restore removed items. render()attaches another event listener every time it runs. One click eventually triggers the same action several times.- The data service catches an error and returns
[]. A failed request is displayed as a successful empty result.
Stop and check
Without looking above, write the seven flow steps on paper. Then explain where you would look first if:
- the request returns 404;
- state contains three items but
visibleItemsis empty; render()receives three items but no DOM elements appear.
What to remember
Do not repair a frontend by guessing. Follow one value and stop at the first place where reality differs from the expected result.