Adds defensive check when validating node title#5464
Adds defensive check when validating node title#5464bjester merged 2 commits intolearningequality:hotfixesfrom
Conversation
| return function (contentNodeId) { | ||
| const contentNode = state.contentNodesMap[contentNodeId]; | ||
| return getNodeDetailsErrors(contentNode); | ||
| return contentNode ? getNodeDetailsErrors(contentNode) : []; |
There was a problem hiding this comment.
getNodeDetailsErrors calls getNodeTitleErrors and the implementation here allowed passing of undefined content nodes thus the error. The other use case in getContentNodeDetailsAreValid (which also calls the getNodeTitleErrors function) handles this edge case correctly. cc @bjester
There was a problem hiding this comment.
This seems better, in that unlike with the previous change, we won't be returning an error about an invalid title when the real error was a missing node. But we're also not returning anything, when a missing node might be problematic. The code in getContentNodeDetailsAreValid would return false with a missing node. This could obscure issues by returning a positive result in a problematic scenario. Adding a new error type might require strings though.
I still wonder if this is happening in a situation that we can actually correct-- one that's caused by code creating this scenario instead of a real scenario a user might encounter. It seems this is only used in the EditView, but getContentNodeDetailsAreValid is also used (I didn't dig deeply). The expectation of a getter like this is that the data has already been loaded into Vuex. Correctly handling that assumption might mitigate this.
So I wonder if this getter is being triggered before the node has been loaded into vuex, which might occur when refreshing the page with the edit modal open, similar to that bug we had when refreshing page with the import modal open. If the result of getContentNodeDetailsAreValid supersedes however this getter is used, then it could return a new error type without us needing to handle the result of that error with new strings.
There was a problem hiding this comment.
Thanks for this! I'll do a little more digging in these lines and see what I can find.
There was a problem hiding this comment.
It doesn't seem that any preloading of required nodes is happening in the EditModal, a possible reason why this error could be triggering, particularly on refresh. Looking at the routing, we should be able to preload the detailNodeIds prior to entering the Edit modal. This, in addition to the defensive check should mitigate the issue, I think!
studio/contentcuration/contentcuration/frontend/channelEdit/router.js
Lines 174 to 229 in ee0de12
There was a problem hiding this comment.
How about this bit of code? Seems like if the catch occurs, perhaps the following then block might encounter a situation where a node hasn't been loaded. Although that code doesn't utilize any of these getters at first glance, but perhaps it later runs into the bug situation. It might be interesting to see whether there are coinciding network errors (e.g. 502s) in sentry for the users who encountered this.
There was a problem hiding this comment.
This seems consistent with all users that triggered the error 🤔
There was a problem hiding this comment.
So technically, the defensive check added should resolve the issue, I think? Probably not... would only suppress it!
There was a problem hiding this comment.
And yes this seems to happen in refreshing the page, pointing back to to your thoughts on the need to preload the detailNodeIds
There was a problem hiding this comment.
Ah sorry, my last comment about it "doesn't utilize any of these getters" was invalid. I was mixing up the two PRs you have open.
Okay so the beforeRouteEnter I linked should preload them, but it also may not complete successfully. It also does some validation but only to mark the nodes' complete. If beforeRouteEnter should preload the nodes into vuex, any insights into where we're going wrong? Are we not properly awaiting something?
There was a problem hiding this comment.
The code in the beforeRouteEnter guard seems functionally correct; the issue arises from a Vue reactivity timing problem between parent and child component where getNodeDetailsErrorsList attempts to access state (content nodes data) before it’s fully initialized. However, once the state is ready, the prop re-triggers the UI update, thus the reason why the UI remains functional. The current fix should effectively resolves the issue without regressions, and should be suitable for now. A more robust solution would require extensive planning and work.
bjester
left a comment
There was a problem hiding this comment.
Based off your investigation, I thinking it would be good to have getNodeDetailsErrorsList return a non-empty array for a missing node and thus getContentNodeDetailsAreValid can be simplified
935f644 to
bbda844
Compare
|
@bjester we should be good after the most recent changes (based on my understanding of your comment above)? |
Not quite what I had in mind. I don't quite understand the latest push. Sorry for the miscommunication. Both Since you were modifying Thus moving all that logic into |
|
Ahh got it--my bad! Thanks for the extra detail! |
bbda844 to
a77e3ed
Compare
|
@bjester, I think we should be good with this? 🤞 |
Summary
This pr adds a defensive on the code for the error reported in sentry as detailed here.
References
Fixes #5433
Reviewer guidance