fix(web-frontend): Coerce preference array fields to prevent TypeError#16
Draft
sentry[bot] wants to merge 1 commit into
Draft
fix(web-frontend): Coerce preference array fields to prevent TypeError#16sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the
TypeError: shiftCount.person.join is not a functionby ensuring that array-typed preference fields are properly normalized during data loading and by adding defensive checks in the rendering component.Changes Made:
web-frontend/src/hooks/useSchedulingData.ts:convertArrayIdsToStringutility with a newnormalizePrefArrayfunction.normalizePrefArraynow actively coerces non-array values (e.g., single strings or numbers from older saved data) into single-element arrays and ensures all IDs are stringified. It also handlesnull/undefinedvalues by returning early.normalizePrefArrayto all relevant array-typed preference fields (e.g.,shiftType,qualifiedPeople,date,person,pattern,countDates,countShiftTypes,people1,people2,shiftTypes) within thenewState.preferences.forEachloop.web-frontend/src/app/shift-counts/page.tsx:Array.isArray()checks aroundshiftCount.person,shiftCount.countDates, andshiftCount.countShiftTypesbefore calling.join(', ')to provide robustness against any data that might bypass the normalization or for future-proofing.Reasoning:
The root cause was that
shiftCount.person(and similar fields likecountDates,countShiftTypes) could be a string or number at runtime, rather than the expectedstring[], leading to aTypeErrorwhen.join()was called. This was due to older persisted data formats and the previous normalization logic inuseSchedulingData.tssilently returning for non-array inputs. The fix ensures these fields are consistently arrays, preventing runtime errors and improving data integrity.Fixes JAVASCRIPT-NEXTJS-H