Skip to content

Fix: Return empty arrays instead of null for device JSON fields#263

Merged
shamanec merged 2 commits intoshamanec:developfrom
mogilevich:fix/null-array-fields
Mar 11, 2026
Merged

Fix: Return empty arrays instead of null for device JSON fields#263
shamanec merged 2 commits intoshamanec:developfrom
mogilevich:fix/null-array-fields

Conversation

@mogilevich
Copy link
Copy Markdown
Contributor

Summary

  • Fix frontend crash (TypeError: Cannot read properties of null (reading 'map')) on device control page caused by supported_stream_types and installed_apps being serialized as null instead of [] in JSON responses.
  • Initialize InstalledApps with make([]string, 0) in GetInstalledAppsIOS and GetInstalledAppsAndroid so error paths return [] not null.
  • Set SupportedStreamTypes based on device OS in provider's DeviceInfo handler (was never set on provider side).
  • Initialize both array fields when creating hub device entries in GetLatestDBDevices.

Root cause

In Go, var s []string is nil, which serializes to JSON null. The frontend calls .map() on these fields, which crashes React when they are null.

Frontend crashes with "Cannot read properties of null (reading 'map')"
when supported_stream_types or installed_apps are null in JSON responses.
Initialize these fields as empty arrays on both hub and provider sides.
@mogilevich
Copy link
Copy Markdown
Contributor Author

How to reproduce

  1. Open the device list at /devices
  2. Click Use on any device (reproduced on iPhone XS, iOS 16.6)
  3. The control page at /devices/control/:udid shows UI for ~1 second, then crashes to a blank screen (just background color)

Browser console

In Use WebSocket connection opened
TypeError: Cannot read properties of null (reading 'map')
    at J3 (main.60dea171.js:1:725196)

API response (/device/:udid/info)

{
  "supported_stream_types": null,
  "installed_apps": null
}

Both fields are null because:

  • SupportedStreamTypes is never set on the provider side
  • InstalledApps uses var s []string which is nil in Go → null in JSON

@gifflet gifflet self-requested a review March 10, 2026 01:49
Copy link
Copy Markdown
Collaborator

@gifflet gifflet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the changes and left some comments inline with suggestions for improvement.

- Add models.StreamTypesForOS() to eliminate OS-to-stream-types switch duplication
- Replace duplicated switch blocks in hub/devices, hub/router, provider/router
- Use unconditional make([]string, 0) for InstalledApps (bson:"-" is always nil from DB)
- Remove redundant comments that restated what code already expressed
@gifflet
Copy link
Copy Markdown
Collaborator

gifflet commented Mar 11, 2026

@mogilevich, everything looks good now. @shamanec, any other considerations before approving?

@shamanec
Copy link
Copy Markdown
Owner

@mogilevich @gifflet supported_stream_types is never read on on the device control page, so I doubt this was part of the issue but other than that - lgtm

@gifflet
Copy link
Copy Markdown
Collaborator

gifflet commented Mar 11, 2026

Yeah, the supported_stream_types fix doesn’t apply to the control page, but it improves api consistency

@shamanec shamanec changed the title fix: return empty arrays instead of null for device JSON fields Fix: Return empty arrays instead of null for device JSON fields Mar 11, 2026
@shamanec
Copy link
Copy Markdown
Owner

thanks for checking it out @gifflet , thank you for the contribution @mogilevich

@shamanec shamanec merged commit f8e0a98 into shamanec:develop Mar 11, 2026
@mogilevich mogilevich deleted the fix/null-array-fields branch March 11, 2026 16:52
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.

3 participants