Skip to content

Fix: Prevent TypeError when mechanical ventilation data is incomplete - #96

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/undefined-mech-vent-map
Open

sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/undefined-mech-vent-map

Conversation

@sentry

@sentry sentry Bot commented Oct 2, 2026

Copy link
Copy Markdown

This PR addresses a TypeError: Cannot read properties of undefined (reading 'map') that occurred in mapping/infiltrationVentilationMapper.ts.

The root cause was that mapMechanicalVentilationData attempted to call .map() on state.infiltrationAndVentilation.mechanicalVentilation without a null guard. The resolveState function (in stores/resolve.ts) only populates this property if the associated form (/infiltration-and-ventilation/mechanical-ventilation) is marked as complete. If a user visited this page but did not complete it before attempting to calculate, mechanicalVentilation would be undefined, leading to the crash.

The fix involves adding a null-coalescing operator (?? []) to ensure that .map() is always called on an array, even if the property is undefined. This pattern is already used elsewhere in the codebase (e.g., for ductwork). The same fix has also been applied to state.infiltrationAndVentilation.vents to prevent a similar potential crash.

Fixes EPB-CHECK-PART-L-FRONTEND-1A

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry at no cost. You can adjust this setting at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants