broadinstitute / seqr

web-based analysis tool for rare disease genomics
GNU Affero General Public License v3.0
176 stars 88 forks source link

Variant Search throws UI error - "TypeError: Cannot read property 'filter' of undefined" #1444

Closed tommyli closed 4 years ago

tommyli commented 4 years ago

Describe the bug

Open any project and click "Project Variant Search" then click "Search" (or any filtered Search that returns some results).

Chrome console log shows the following:

httpRequestHelper.js:123 TypeError: Cannot read property 'filter' of undefined
    at eval (selectors.js:680)
    at Array.reduce (<anonymous>)
    at eval (selectors.js:679)
    at eval (index.js:76)
    at eval (index.js:37)
    at eval (index.js:89)
    at eval (index.js:37)
    at Function.mapStateToProps [as mapToProps] (FamilyVariantTags.jsx:431)
    at mapToPropsProxy (wrapMapToProps.js:46)
    at Function.detectFactoryAndVerify (wrapMapToProps.js:55)

After triage, here are my findings:

I suspect this only happens to "Staff" users or any users who has access to multiple projects. Immediately after logging in, users are presented all projects he/she has access to and at this point, the redux state has projectsByGuid populated for all projects with summary info. Selecting a project and then clicking on "Project Variant Search", the redux store maintains this state for all projects in state.projectsByGuid. See first screenshot below.

When search results return from the server and UI tries to render the results, the above 'filter' undfined error gets thrown. This is because in ui/redux/selectors.js -> the createSelector() for getTagTypesByProject has project.variantTagTypes as undefined for all projects (except the project under search) at that point and hence the error.

Navigating to project page (bypassing project listing page) directly prevents this issue, i.e. navigating to http://localhost:3000/variant_search/project/R0013_dt_001 then doing the same search returns no error because navigating to the project directly, the redux state already has projectsByGuid filtered to the corresponding project. See second screenshot below.

As a workaround, I've changed this line (should be line 418 in ui/redux/selectors.js) in our codebase:

[project.projectGuid]: project.variantTagTypes.filter(vtt => vtt.name !== NOTE_TAG_NAME),

to:

[project.projectGuid]: (project.variantTagTypes || []).filter(vtt => vtt.name !== NOTE_TAG_NAME),.

Scope of the bug

This issue is happening on my machine after merging in latest upstream/master changes (as of 2020-09-02). Latest upstream/master commit is 67f9cfd6db4870a0a618c6b88c339a712dca3ca2 - "Merge pull request #1441 from macarthur-lab/dev". This is for work at MCRI Seqr instance.

There has been very little customisations, all in the backend and none in the UI.

Screenshots

redux_state_variant_search_from_project_listings

our problem.

redux_state_variant_search_from_project_page
hanars commented 4 years ago

the workaround fix you posted here is probably what we want to do. Do you mind putting up a pull request for it? I can manage building the assets and all that