Skip to content

refactor(sidebar): use external-store viewport subscriptions - #602

Open
IzumiSy wants to merge 1 commit into
mainfrom
refactor/responsive-hook-subscriptions
Open

IzumiSy wants to merge 1 commit into
mainfrom
refactor/responsive-hook-subscriptions

Conversation

@IzumiSy

@IzumiSy IzumiSy commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

The sidebar's mobile and tablet hooks currently subscribe to matchMedia and copy the viewport into React state through effects. Both initially return false, so client-only rendering starts with desktop assumptions even when the actual viewport is mobile or tablet.

The effects synchronously update the viewport state after the first commit, triggering an additional render solely to copy a browser-owned value into React state.

This extracts the responsive-hook changes from #525 into an independent PR based on main, without the lint upgrade or the other state-ownership changes.

Design Decision

Subscribe directly to the browser-owned viewport

Use useSyncExternalStore in the two existing hooks, retaining their current innerWidth predicates and media-query subscriptions. Module-level subscription functions remain stable across rerenders and remove the same listeners on unmount. No shared hook abstraction or public API is added.

Preserve server rendering and hydration

Both server snapshots remain false. Server rendering and the first hydration render therefore retain the existing desktop fallback; client-only rendering reads the actual viewport immediately.

The desktop Sidebar test fixture moves from 1024px, which lies in the tablet range, to 1200px. A separate 1024px assertion retains coverage of the tablet icon rail rather than relying on the temporary desktop fallback.

Summary

  • Replace effect-mirrored state in the mobile/tablet hooks with stable external-store subscriptions.
  • Cover breakpoint boundaries, first client render, change notifications, subscription cleanup, SSR, and hydration.
  • Correct the desktop Sidebar fixture, explicitly cover tablet layout, and add a patch changeset for the initial-render behavior change.

@github-actions

Copy link
Copy Markdown
Contributor

Code Metrics Report

main (d8d4ec3) #602 (4194321) +/-
Coverage 88.6% 88.6% +0.0%
Test Execution Time 1m53s 1m31s -22s
Details
  |                     | main (d8d4ec3) | #602 (4194321) |  +/-  |
  |---------------------|----------------|----------------|-------|
+ | Coverage            |          88.6% |          88.6% | +0.0% |
  |   Files             |            208 |            208 |     0 |
  |   Lines             |           6263 |           6260 |    -3 |
- |   Covered           |           5552 |           5551 |    -1 |
+ | Test Execution Time |          1m53s |          1m31s |  -22s |

Code coverage of files in pull request scope (90.4% → 100.0%, patch 100.0%)

Files Coverage +/- Patch Coverage Status
packages/core/src/hooks/use-mobile.ts 100.0% +10.0% 100.0% modified
packages/core/src/hooks/use-tablet.ts 100.0% +9.0% 100.0% modified

Reported by octocov

@IzumiSy
IzumiSy marked this pull request as ready for review October 13, 2026 04:37
@IzumiSy
IzumiSy requested a review from a team as a code owner October 13, 2026 04:37
@IzumiSy

IzumiSy commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Code Review completed successfully!

Code review complete for PR #602 package changes. No actionable High/Medium issues found in the packages/** diff, so no inline review comment was needed.

Generated by Code Review for #602

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