Skip to content

chore: hoist useDriverLivePositions from TrackCanvas to TrackMap - #567

Merged
tariknz merged 2 commits into
mainfrom
fix/trackcanvas-stories-running-state
May 29, 2026
Merged

chore: hoist useDriverLivePositions from TrackCanvas to TrackMap#567
tariknz merged 2 commits into
mainfrom
fix/trackcanvas-stories-running-state

Conversation

@tariknz

@tariknz tariknz commented May 27, 2026

Copy link
Copy Markdown
Owner

Description

TrackCanvas's Storybook stories were failing with useRunningState must be used within a RunningStateProvider after #551 added a disconnect-reset effect inside useDriverLivePositions (which TrackCanvas called transitively).

The fix has two parts:

  1. Hoist useDriverLivePositions from TrackCanvas to TrackMapTrackMap is the data-wiring layer; it already calls useDriverProgress, useSectorColors, etc. The result is passed to TrackCanvas as a driverLivePositions prop (defaults to {}), mirroring how driverIdentities is already handled. TrackCanvas becomes one step more presentational and its stories no longer require RunningStateProvider plumbing.
  2. Mount RunningStateProvider inside TelemetryDecorator — so TrackMap (and any other story consuming useDriverLivePositions transitively) works in Storybook. The mock bridge from generateMockDataFromPath already implements onRunningState. While here, widened RunningStateProvider's bridge prop to IrSdkBridge | Promise<IrSdkBridge> for parity with SessionProvider / TelemetryProvider.

No runtime behaviour change in the app — TrackMap calls the hook with the same enabled predicate (settings?.displayMode === 'livePosition'), and useDriverLivePositions's subscriptions / memoization are unchanged.

Verified locally: npm test (842 tests, all pass), npm run lint clean, typecheck clean, TrackCanvas + TrackMap stories render in Storybook.

Screenshots

Before

http://localhost:6006/?path=/story/widgets-trackmap-components-trackcanvas--primary throws:

useRunningState must be used within a RunningStateProvider

After

TrackCanvas and TrackMap stories both render correctly.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring (no functional changes)

Checklist

  • All tests pass locally via `npm test`
  • I have run `npm run lint` and fixed any issues
  • I have performed a self-review of my own code
  • I have added/updated Storybook stories for visual changes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Restructured track map components to improve live driver position display, now dynamically enabled based on display mode settings.
    • Extended provider infrastructure to support both direct and asynchronous initialization methods.
    • Updated development environment test decorator configuration.
  • Tests

    • Added and updated mock dependencies for track map component testing.

Review Change Stack

TrackCanvas's Storybook stories were failing with "useRunningState must
be used within a RunningStateProvider" after #551 added a disconnect-reset
inside useDriverLivePositions. Move the hook call to TrackMap (the
data-wiring layer) and pass driverLivePositions to TrackCanvas as a prop,
mirroring how driverIdentities is already handled. TrackCanvas becomes
more presentational and its stories no longer need provider plumbing.

TelemetryDecorator now also mounts RunningStateProvider so TrackMap
(and any other widget consuming useDriverLivePositions transitively)
works in Storybook. RunningStateProvider's bridge prop widened to
IrSdkBridge | Promise<IrSdkBridge> for parity with SessionProvider and
TelemetryProvider.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR lifts the useDriverLivePositions hook from TrackCanvas to TrackMap as a prop, extends RunningStateProvider to accept promise-based bridges, and refactors the Storybook telemetry decorator to use RunningStateProvider with promise support.

Changes

Driver state and provider refactoring

Layer / File(s) Summary
RunningStateProvider promise bridge support
src/frontend/context/RunningStateContext/RunningStateContext.tsx
RunningStateProviderProps.bridge is broadened to accept IrSdkBridge | Promise<IrSdkBridge>. The useEffect conditionally resolves promise bridges, guards listener registration with a cancellation flag to prevent side effects after unmount, and ensures cleanup unsubscribes and stops the bridge.
Storybook decorator refactoring with RunningStateProvider
.storybook/telemetryDecorator.tsx
TelemetryDecorator is refactored to an explicit DecoratorComponent with displayName. TelemetryDecoratorWithConfig wraps Story with RunningStateProvider using generateMockDataFromPath(path), extending the provider hierarchy to include RunningStateProvider.
Lift driver live positions from TrackCanvas to TrackMap
src/frontend/components/TrackMap/TrackCanvas.tsx, src/frontend/components/TrackMap/TrackMap.tsx, src/frontend/components/TrackMap/TrackMap.spec.tsx
TrackCanvas removes the useDriverLivePositions hook and accepts driverLivePositions as an optional prop. TrackMap conditionally calls useDriverLivePositions when displayMode is 'livePosition' and passes the result to TrackCanvas. Tests mock the hook dependency.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit hops through the refactor flow,
Lifting state higher, watching code grow,
Promises resolved with grace and care,
Driver positions float through the air,
Decorators dance in Storybook's show! 🎭

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description covers all key template sections: clear problem/solution description, before/after screenshots, appropriate type of change checkboxes, and relevant checklist items completed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The PR title 'chore: hoist useDriverLivePositions from TrackCanvas to TrackMap' accurately describes the main refactoring change and is specific, clear, and reflects the primary objective of hoisting a hook call to a higher component level.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/trackcanvas-stories-running-state

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tariknz tariknz changed the title refactor: hoist useDriverLivePositions from TrackCanvas to TrackMap chore: hoist useDriverLivePositions from TrackCanvas to TrackMap May 28, 2026
@tariknz
tariknz merged commit b73e45d into main May 29, 2026
2 checks passed
@tariknz
tariknz deleted the fix/trackcanvas-stories-running-state branch May 29, 2026 21:46
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.

1 participant