Skip to content

fix: keep live card counts and follow suggestions in sync - #1477

Merged
xHeaven merged 3 commits into
productionfrom
fix/realtime-button-and-suggestions
Nov 4, 2026
Merged

xHeaven merged 3 commits into
productionfrom
fix/realtime-button-and-suggestions

Conversation

@xHeaven

@xHeaven xHeaven commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Fix live card counts becoming stale after hovering a star, and Who to follow controls staying stale after a follow or dismissal in another tab. Tooltips retain their lazy mounting.

Changes

  • Re-register a card when its star button is replaced. The shared card read keeps stars, pastéis and reply counts current.
  • Reconcile the loaded suggestions on private updates, reconnect and tab return. Follow buttons change in place; dismissed suggestions use the existing spare-slot replacement without reshuffling the other rows.
  • Add a private dismissal announcement and a bounded, authenticated state read. No regular polling interval, dependencies or migrations are added.
  • Protect local optimistic follows and discard reads belonging to an old account or unmounted sidebar.

Validation

  • composer test:lint, composer test:types, composer test:type-coverage: passed; type coverage 100%.
  • bun run test:unit: 269 passed.
  • bunx vp test run tests/Unit/*.test.tsx: 1,033 passed in 103 files.
  • bun run build: passed.
  • PHP CI suite with --ci --coverage --exactly=100.0: 5,781 passed, 31,271 assertions, exactly 100% coverage (isolated local PostgreSQL). PHP files are unchanged by the final frontend recovery correction.
  • Regression tests cover replaced/detached buttons, shared pastéis counts, follow/dismissal events, cached suggestions, hidden tabs, reconnect, read failure and stale-account responses. The button and sidebar tests failed before the fixes.
  • No post-fix browser or device session was performed. This changes synchronization and element registration; tooltip rendering, UI markup/styles, touch controls and keyboard layouts are unchanged.

Independent review

Independent read-only Codex review: CODE PASS / scoped VISUAL PASS. All 16 changed files and all three commits reviewed; 73 focused tests and 10 independent reproduction tests passed. Visual scope is unchanged presentation and device mechanics; no post-fix GUI/device validation was claimed. Reviewed at 03a95b7b → c0960d48.

Limitations

A failed suggestion-state read retries on the next relevant event, rejoin or tab return. Existing call and inbox safety polling is unchanged. This does not refresh suggestion recommendation reasons or follow-back badges when another person follows you.

Summary by CodeRabbit

  • New Features
    • Follow changes and dismissed suggestions now synchronize across open tabs. The “Who to follow” list updates to reflect those changes while preserving other suggestions.
    • Suggestion state refreshes when you return to a tab, helping keep the list current after missed updates.
  • Bug Fixes
    • Follow actions are protected from stale updates, so a delayed refresh won’t undo a recent follow change.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds an authenticated endpoint for suggested-user follow and dismissal state, emits suggestion updates after new dismissals, and reconciles suggestions in the browser. It also changes how the commit-star button tracks its subscribed element.

Changes: Suggestion state synchronization

Layer / File(s) Summary
Suggestion state API and dismissal events
app/Enums/UserUpdate.php, app/Actions/CreateSuggestionDismissal.php, app/Http/Requests/ListSuggestedUserStatesRequest.php, app/Queries/SuggestedUserStatesQuery.php, app/Http/Controllers/SuggestedUserStateController.php, routes/web.php, tests/Feature/Controllers/SuggestedUserStateControllerTest.php, tests/Feature/Controllers/SuggestionDismissalControllerTest.php
Adds a validated endpoint that returns follow and dismissal flags for requested IDs. A new dismissal dispatches a UsersUpdated event with the Suggestions update type. Feature tests cover response data, authorization, input validation, caching, and event dispatch.
Client-side suggestion reconciliation
resources/js/components/follow-button.tsx, resources/js/components/who-to-follow.tsx, tests/Unit/FollowState.test.tsx, tests/Unit/WhoToFollowRealtime.test.tsx, KNOWLEDGE_BASE.md
The client requests state on relevant events and when a hidden tab becomes visible. It applies follow updates without overriding newer local follows, removes remotely dismissed suggestions, and tops up the list. Tests cover these paths and the knowledge-base description records cross-tab synchronization.

Commit-star element subscriptions

Layer / File(s) Summary
Track the current commit-star element
resources/js/components/commit-star-button.tsx, tests/Unit/CommitStarElement.test.tsx, tests/Unit/CommitStarSubscriptions.test.tsx
The polling effect uses state to track the attached element and reruns when that element changes. Tests cover replacement, detachment, and updates to the replacement card subscription.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant WhoToFollow
  participant UserChannel
  participant SuggestedUserStateController
  participant SuggestedUserStatesQuery
  UserChannel-->>WhoToFollow: UsersUpdated event
  WhoToFollow->>SuggestedUserStateController: GET suggested-user-states with suggestion IDs
  SuggestedUserStateController->>SuggestedUserStatesQuery: get(viewer, ids)
  SuggestedUserStatesQuery-->>SuggestedUserStateController: follow and dismissal flags
  SuggestedUserStateController-->>WhoToFollow: users JSON
  WhoToFollow->>WhoToFollow: update follow state and remove dismissed suggestions
Loading

Possibly related PRs

Suggested reviewers: mnapoli

Merge Risk: Minimal · up to c0960

No merge-blocking issue was identified; the suggestion-state and commit-star changes are ready for normal checks.

Security architecture risk: Low · up to c0960

The new read is authenticated, bounded and scoped to the signed-in user. Dismissal notifications carry no relationship details. No introduced authorization bypass or cross-account disclosure was established. Remaining uncertainty concerns shared browser-state cleanup during account transitions.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — An authenticated caller can choose up to 100 target UUIDs per read, but the returned relationship flags are computed only from that caller's relationships. The live-reads limiter allows 60 requests per minute keyed by authenticated user, with an IP fallback.

Trust Boundaries and Controls

  • observed — Caller-controlled IDs cross list and UUID validation before reaching database relationship reads. The viewer identity instead comes from CurrentUser under route authentication. Responses are private and no-store; inspected tests assert unauthenticated rejection and separation between two viewers' state.

Resilience and Maintainability Implications

  • observed — The reconciliation effect owns an abort controller, subscription and visibility listener. Viewer or loaded-ID changes and unmount clean them up; aborted responses are rejected before applying state. The stale-account test covers a delayed read after the viewer prop changes, but not every pending dismissal or top-up transition across accounts.
  • observed — The new notification reuses an event implementing after-commit dispatch and broadcast-failure rescue. Sequential repeated dismissals do not announce another update unless a relationship was newly attached. Lost notifications are recoverable through the client's subsequent authoritative reads rather than a durable event log.

Hardening Proposals

  • proposed — If account changes can reuse the same browser application context, namespace or reset viewer-relative shared state and bind delayed top-up callbacks to viewer identity. Target-keyed state and module-scoped dismissal tracking already existed before this PR; this is defense in depth, not an established new disclosure.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely summarizes the two main changes: synchronizing live card counts and follow suggestions.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 15 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c20f9030-4fdd-4b1d-897f-99934b871f70
Commits

Reviewing files that changed from the base of the PR and between 03a95b7 and c0960d4.

Files selected for processing: 16
  • KNOWLEDGE_BASE.md
  • app/Actions/CreateSuggestionDismissal.php
  • app/Enums/UserUpdate.php
  • app/Http/Controllers/SuggestedUserStateController.php
  • app/Http/Requests/ListSuggestedUserStatesRequest.php
  • app/Queries/SuggestedUserStatesQuery.php
  • resources/js/components/commit-star-button.tsx
  • resources/js/components/follow-button.tsx
  • resources/js/components/who-to-follow.tsx
  • routes/web.php
  • tests/Feature/Controllers/SuggestedUserStateControllerTest.php
  • tests/Feature/Controllers/SuggestionDismissalControllerTest.php
  • tests/Unit/CommitStarElement.test.tsx
  • tests/Unit/CommitStarSubscriptions.test.tsx
  • tests/Unit/FollowState.test.tsx
  • tests/Unit/WhoToFollowRealtime.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@xHeaven
xHeaven merged commit 74f91e2 into production Nov 4, 2026
15 checks passed
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