Skip to content

refactor: consolidate viewport hooks and remove defineProperty matchMedia stub - #28460

Merged
ibetitsmike merged 4 commits into
mainfrom
mike/viewport-hook-consolidation
Aug 24, 2026
Merged

refactor: consolidate viewport hooks and remove defineProperty matchMedia stub#28460
ibetitsmike merged 4 commits into
mainfrom
mike/viewport-hook-consolidation

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to review feedback on #28387.

That PR added three hooks for one feature (useIsBelowLgViewport, useIsBelowMdViewport, and the local single-use useRightPanelNarrowSuppression) and stubbed window.matchMedia in tests with Object.defineProperty.

  • Replace the two single-purpose viewport hooks with one generic useMediaQuery(query). Callers pass the shared Tailwind-aligned query constants from utils/mobile.ts. The one new hook replaces the two deleted ones (net -1).
  • Inline useRightPanelNarrowSuppression into AgentChatPage, its only consumer, and drop its renderHook unit suite. The behavior stays covered by the narrow-viewport stories; the widening-restore case moved into the NarrowingSuppressesExpandedPanel play function.
  • Rework testHelpers/matchMedia.ts to install the stub with spyOn from storybook/test instead of Object.defineProperty. The helper is story-only now (stories run in real Chromium; jsdom has no matchMedia), so any future unit test needing a stub should use vi.stubGlobal directly.
  • Encode the feedback in the canonical FE contract so it gets caught during development: .claude/docs/FRONTEND_PATTERNS.md now bans new React hooks when an existing hook, a plain function, or component state suffices (FE3) and bans replacing browser globals with Object.defineProperty in tests or stories (FE9: vi.stubGlobal / spyOn), and notes that renderHook suites for stateful UI hooks belong in the consuming component's story (FE1). The frontend-review skill checklist flags all three. site/AGENTS.md is unchanged since it already defers to the patterns doc.

Validation: pnpm check, pnpm format:check, pnpm lint (biome, types, knip, circular deps, compiler check), AgentChatPage.test.ts (70 passed), story runs for AgentChatPage.stories.tsx and WorkspacePill.stories.tsx (49 passed in Chromium).

Xum acted on Mike's behalf (@ibetitsmike).

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 9369950c91

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike ibetitsmike changed the title refactor(site): consolidate viewport hooks and remove defineProperty matchMedia stub refactor: consolidate viewport hooks and remove defineProperty matchMedia stub Aug 24, 2026
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: ad4acc562a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 585ec968d9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: c1b0c827bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jeremyruppel jeremyruppel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! thanks for these fixups!

@ibetitsmike
ibetitsmike force-pushed the mike/viewport-hook-consolidation branch from c1b0c82 to 021243d Compare August 24, 2026 16:44
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@ibetitsmike
ibetitsmike enabled auto-merge (squash) August 24, 2026 16:49
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 021243d9ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike merged commit 3c32408 into main Aug 24, 2026
26 checks passed
@ibetitsmike
ibetitsmike deleted the mike/viewport-hook-consolidation branch August 24, 2026 16:52
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants