Skip to content

fix: register CarPlayDashboard before dashboard connects#87

Merged
g4rb4g3 merged 1 commit into
Iternio-Planning-AB:masterfrom
LukasB-DEV:fix-carplay-dashboard-registration
May 28, 2026
Merged

fix: register CarPlayDashboard before dashboard connects#87
g4rb4g3 merged 1 commit into
Iternio-Planning-AB:masterfrom
LukasB-DEV:fix-carplay-dashboard-registration

Conversation

@LukasB-DEV

Copy link
Copy Markdown
Contributor

Problem

CarPlayDashboard is currently only registered with React Native's AppRegistry after the dashboard scene reports didConnect.

That makes the dashboard root component registration depend on the CarPlay connection lifecycle. In some reload/reconnect flows, the native dashboard scene can request a React root view for the CarPlayDashboard module before JS has received a fresh didConnect event again.

In that case React Native throws:

Invariant Violation: "CarPlayDashboard" has not been registered.

Reproduction

In a consuming app using CarPlayDashboard.setComponent(...):

  1. Start the app with CarPlay enabled.
  2. Open the CarPlay Dashboard scene.
  3. Close/disconnect the CarPlay scene.
  4. Reload the React Native app / Metro while the dashboard scene lifecycle is still around or reconnect CarPlay afterwards.
  5. The native side can try to create a root view for CarPlayDashboard before JS registers the component again.

Observed result:

"CarPlayDashboard" has not been registered

Expected result:

CarPlayDashboard should be registered once the JS component is provided via setComponent(...). Native root view initialization should still only happen while the dashboard scene is connected.

What Changed

  • Register the CarPlayDashboard component as soon as setComponent(...) has provided the component.
  • Keep HybridCarPlayDashboard.initRootView() guarded by the current isConnected state.
  • Add a small componentRegistered guard so reconnects do not repeatedly call AppRegistry.registerComponent(...).

Why

AppRegistry.registerComponent(...) is JS runtime setup and does not need an active CarPlay Dashboard connection.

initRootView() is the part that needs the native dashboard scene/window to be connected, so that remains connection-gated.

This keeps the existing native lifecycle behavior intact while making the JS module registration deterministic across reloads and reconnects.

Testing

  • Verified in a consuming app that the iOS simulator build succeeds.
  • Verified that CarPlayDashboard is registered before native dashboard root view initialization is requested.
  • Existing dashboard initialization still only calls initRootView() when the dashboard is connected.

@github-actions

Copy link
Copy Markdown
Contributor

No significant issues found.

@SamuelBrucksch

Copy link
Copy Markdown
Contributor

@claude please review

@claude

claude Bot commented May 21, 2026

Copy link
Copy Markdown

Claude finished @SamuelBrucksch's task in 40s —— View job


Review of PR #87

  • Gather context and read changed files
  • Review the diff against origin/master
  • Post review feedback

Feedback

No issues found. The change is correct and well-scoped.

The separation of AppRegistry.registerComponent() (JS-only setup) from initRootView() (requires native connection) is the right fix. The componentRegistered guard is appropriate given that setComponent already enforces single-call semantics (line 79 throws on a second call), so the guard only needs to protect against the setIsConnected → registerComponent path re-registering on reconnect.


@SamuelBrucksch

Copy link
Copy Markdown
Contributor

@g4rb4g3 do you have anything to add? If not I'll merge it.

@g4rb4g3

g4rb4g3 commented May 28, 2026

Copy link
Copy Markdown
Contributor

Nope, looks reasonable. Thank you @LukasB-DEV !

@g4rb4g3 g4rb4g3 merged commit ac1943f into Iternio-Planning-AB:master May 28, 2026
3 checks passed
@SamuelBrucksch

SamuelBrucksch commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

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