Skip board list count updates for lists not in the cache
What does this MR do and why?
Fixes an uncaught TypeError on issue boards after an issue is created in a list or moved between lists.
updateIssueCountAndWeight and updateEpicsCount in app/assets/javascripts/boards/graphql/cache_updates.js update the cached issue count and total weight of the source and target lists with Apollo's cache.updateQuery. That method reads the list query from the cache and passes the result to an updater. When the list query has not run yet, for example for a list that has not rendered, there is no cache entry and the updater receives null.
The updaters destructured the argument directly, as ({ boardList }) => ... and ({ epicBoardList }) => .... With null that threw:
TypeError: Cannot destructure property 'boardList' of 'object null' as it is null.Apollo logs errors thrown inside updateQuery through invariant.error, so the console shows an uncaught error with a stack that points at vendor.dll.bundle.js.
In CI this logged the error in 3 examples of ee/spec/features/boards/new_issue_spec.rb, which create an issue from a board list.
Changes made:
app/assets/javascripts/boards/graphql/cache_updates.js— the updaters now takedataand returndata && { ... }. For a list that is not cached they return null, which makesupdateQueryleave the cache untouched. For a cached list the write is unchanged. The epic board updaters have the same shape and get the same guard.spec/frontend/boards/cache_updates_spec.js— newupdateIssueCountAndWeightblock with a small cache double that mimicsupdateQuery. Two cases: both lists cached, so both counts and weights update; one list not cached, so nothing throws and nothing is written.
How to set up and validate locally
- Open a project issue board with at least two lists.
- Open the DevTools console.
- In the first list, use the list's "Create new issue" action to create an issue and submit.
- Check the console shows no
Cannot destructure property 'boardList'error. - Drag the issue to the other list and check the list counts in the headers update.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
- I have evaluated the MR acceptance checklist for this MR.
References
- Addresses one entry of #628901 (browser console error catalogue, section B)
- Errors surfaced by !255207 (closed) (feature specs fail on console errors)
- Sibling fixes from the same catalogue: !255305 (merged), !255309 (merged), !255311 (merged), !255313 (merged), !255315 (merged), !255316 (merged), !255319 (merged), !255321 (merged), !255322 (merged)