Skip to content

Sprint 5: Bindings & Interactivity — migrate React hooks to UI#70

Merged
pipewrk merged 7 commits intosprint/5-move-hooks-to-uifrom
move-react-hooks-to-ui-package
Oct 7, 2025
Merged

Sprint 5: Bindings & Interactivity — migrate React hooks to UI#70
pipewrk merged 7 commits intosprint/5-move-hooks-to-uifrom
move-react-hooks-to-ui-package

Conversation

@pipewrk
Copy link
Contributor

@pipewrk pipewrk commented Oct 6, 2025

Summary

Sprint 5: Bindings & Interactivity — migrate React hooks to UI.

Sprint: 5 (Bindings & Interactivity)
Scope: policy · resource · data · ui · docs

Links

Why

React-facing hooks lived in @geekist/wp-kernel, tying the kernel package to React and WordPress data availability. Moving them into the UI package keeps the kernel transport-agnostic while providing a single UI integration surface.

What

  • Migrated useKernel, usePolicy, and resource useGet/useList helpers (plus tests) into @geekist/wp-kernel-ui, exposing globals so kernel resources attach hooks automatically once the UI bundle loads.
  • Updated kernel exports, globals, and types to rely on UI-provided hooks while keeping cache/prefetch behaviour intact.
  • Documented the new hook locations across API, guides, and quick start docs; refreshed changelog entries for kernel and UI packages.

How

Hook implementations now live beside UI components and rely on kernel runtime globals for registration. defineResource() looks for a UI-provided global to attach hooks lazily, and documentation calls out the requirement to import @geekist/wp-kernel-ui when bootstrapping UI code. Legacy kernel tests were relocated and expanded under the UI package to preserve coverage.

Testing

How reviewers test locally:

  1. CI=1 pnpm lint --fix
  2. CI=1 pnpm typecheck && CI=1 pnpm typecheck:tests
  3. CI=1 pnpm test
  4. CI=1 pnpm build
    Expected: All commands succeed without errors; tests remain green with full coverage.

Test Matrix (tick what’s covered)

  • Unit (pnpm test)
  • E2E (pnpm e2e)
  • Types (pnpm typecheck)
  • Docs examples (build/run)
  • WordPress playground / wp-env sanity

Screenshots / Recordings (if applicable)

N/A

Breaking Changes

  • None

Affected Packages

  • @geekist/wp-kernel
  • @geekist/wp-kernel-ui
  • @geekist/wp-kernel-cli
  • @geekist/wp-kernel-e2e-utils

Release

  • minor — feature sprint (default)
  • patch — bugfixes / alignment
  • major — breaking API

Checklist

  • Tests pass (pnpm test, where relevant: pnpm e2e)
  • Lint passes (pnpm lint)
  • Types pass (pnpm typecheck, pnpm typecheck:tests)
  • Changeset added/updated (or PR labelled no-release)
  • Docs updated (site/README)
  • Examples updated (if API changed)

https://chatgpt.com/codex/tasks/task_e_68e3cf789f148325ae4fbe555d4052be

Copilot AI review requested due to automatic review settings October 6, 2025 23:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates React-facing hooks (useKernel, usePolicy, and resource hooks) from @geekist/wp-kernel to @geekist/wp-kernel-ui, making the kernel package transport-agnostic while consolidating UI integrations into a single package.

Key changes:

  • Moved React hooks to UI package with global registration pattern for automatic resource hook attachment
  • Updated documentation and exports to reflect new hook locations
  • Preserved test coverage by relocating and expanding tests in the UI package

Reviewed Changes

Copilot reviewed 32 out of 34 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/ui/src/index.ts Updated exports to include migrated hooks instead of placeholder comments
packages/ui/src/hooks/usePolicy.ts New implementation of usePolicy hook with runtime global resolution
packages/ui/src/hooks/useKernel.ts Migrated useKernel implementation with kernel imports
packages/ui/src/hooks/resource-hooks.ts New resource hook implementations with global attachment mechanism
packages/ui/src/hooks/tests/*.test.ts Migrated and updated test files for all hook implementations
packages/ui/package.json Added @wordpress/data peer dependency
packages/kernel/src/resource/define.ts Removed inline hook implementations, added global hook attachment
packages/kernel/src/policy/index.ts Removed usePolicy export
packages/kernel/src/index.ts Removed useKernel and usePolicy exports
docs/* Updated documentation to reference new hook locations

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ 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

pipewrk and others added 2 commits October 7, 2025 08:20
…gurations

- Fixed import paths in useKernel.ts to use specific module paths for better tree-shaking
- Removed unnecessary type assertions in useKernel.test.ts, using proper mock types
- Added comment referencing shared global type definition in resource-hooks.ts
- Fixed resource-hooks.test.ts mock to return undefined instead of null
- Fixed TypeScript project references configuration:
  - Removed incompatible 'noEmit: true' from test configs (kernel & ui packages)
  - Added packages/ui/tsconfig.tests.json reference to root tsconfig.json
  - Added global types to UI test config include paths
- All tests passing: 947 total (945 passed, 2 skipped)
- All typecheck validations passing
@pipewrk pipewrk requested a review from Copilot October 7, 2025 09:24
@pipewrk
Copy link
Contributor Author

pipewrk commented Oct 7, 2025

@codex please review again and ensure your previous feedback is addressed

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 58 out of 62 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

packages/ui/src/hooks/useVisiblePrefetch.ts:1

  • The ! non-null assertions are potentially unsafe here since values[0] could be undefined if tokens is empty. Consider adding a guard condition or defaulting to '0px' when tokens.length === 0.
import { useEffect, useMemo, useRef } from 'react';

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ 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

- Refactor complex type assertion chain in ensureDispatch()
- Extract invokeMethod after type guard for cleaner code flow
- Add explanatory comment for generic type casting responsibility
- Document intentional primitive throw in test case for error normalization

Addresses Copilot PR feedback #70 comments 5-6
@pipewrk pipewrk requested a review from Copilot October 7, 2025 09:33
@pipewrk
Copy link
Contributor Author

pipewrk commented Oct 7, 2025

@codex fixed your previous issues, review again please

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 58 out of 62 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

packages/ui/src/hooks/useAction.ts:1

  • Throwing a primitive string instead of an Error object is an anti-pattern that makes error handling less predictable. Consider throwing new Error('primitive failure') to maintain consistency with JavaScript error handling conventions.
import { useCallback, useMemo, useRef, useState } from 'react';

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ 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

- Add module-level queue for resources created before UI bundle loads
- Kernel side: Queue resources and expose __WP_KERNEL_UI_PROCESS_PENDING_RESOURCES__
- UI side: Process pending queue when resource-hooks.ts module loads
- Add global type definition for process function
- Fixes timing issue where resources defined before UI never get React hooks

Addresses P1 review comment from PR #70
@pipewrk pipewrk requested a review from Copilot October 7, 2025 10:05
@pipewrk
Copy link
Contributor Author

pipewrk commented Oct 7, 2025

@codex any P1 or P2 issues?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 58 out of 62 changed files in this pull request and generated 3 comments.

@chatgpt-codex-connector
Copy link

Findings

  • The earlier P1 about resource hooks missing when the UI bundle loads late appears addressed: defineResource now queues pre-UI resources and exposes __WP_KERNEL_UI_PROCESS_PENDING_RESOURCES__, and the UI bundle consumes that queue to backfill useGet/useList. packages/kernel/src/resource/define.tsL31-L395 packages/ui/src/hooks/resource-hooks.tsL1-L180
  • One P1 remains: in the 'queue' concurrency mode, cancelling the hook does not stop already-queued calls. run() stores a next promise that always calls start() once the current run settles; cancelAll() only nulls queueTailRef.current and marks current records, so queued start() executions still fire after cancellation. This contradicts the documented cancellation behavior and lets cancelled actions mutate state. packages/ui/src/hooks/useAction.tsL337-L410

Recommendation

  • Address the outstanding useAction queue cancellation bug (P1) so that cancelling the hook prevents any queued work from executing.

View task →

All Review Comments Resolved
- Fixed import path issues (relative and absolute paths)
- Improved type assertions with detailed explanatory comments
- Enhanced JSDoc documentation for all new functionality
- Fixed tsconfig test paths and configurations
- Resolved resource hook timing issue with queuing mechanism
- Fixed queue cancellation bug using cancellation token

Comprehensive JSDoc Documentation
- Added module-level documentation for resource-hooks.ts
- Documented lazy binding and pending resource queue system
- Enhanced type assertions with detailed explanations
- Added comments for global hook registration
- Documented WordPress data store integration patterns

Expanded Test Coverage (89.73 percent branches)
Added 50 plus new tests for uncovered branches:
- resource-hooks.test.ts: SSR handling, pending queue processing
- useAction.test.tsx: error paths, concurrency modes, cancellation
- useVisiblePrefetch.test.tsx: SSR handling, margin parsing, observer edge cases
- useHoverPrefetch.test.tsx: unmount cancellation, listener cleanup
- useKernel.test.tsx: middleware handling and cleanup
- usePolicy.test.tsx: promise rejection, runtime errors, success scenarios

Bug Fixes
- Fixed queue cancellation logic with queueCancelledRef
- Implemented resource hook lazy binding with pending queue
- Corrected non-null assertions in useVisiblePrefetch
- Added type guard for WordPress data store dispatch
- Improved error normalization in useAction hook

Coverage Improvements
- Overall: 97.00 percent statements, 89.73 percent branches, 98.01 percent functions
- All UI hooks meet or exceed branch coverage thresholds
- Comprehensive edge case testing, no regressions

All tests passing (970 of 972), all type checks green.

Refs: #70

Refs: #70
@pipewrk
Copy link
Contributor Author

pipewrk commented Oct 7, 2025

@codex, I believe all issues resolved?

@chatgpt-codex-connector
Copy link

Summary

Testing

  • CI=1 pnpm test
  • CI=1 pnpm typecheck

View task →

@pipewrk pipewrk merged commit 6317968 into sprint/5-move-hooks-to-ui Oct 7, 2025
@pipewrk pipewrk deleted the move-react-hooks-to-ui-package branch October 14, 2025 10:10
pipewrk added a commit that referenced this pull request Nov 8, 2025
…gurations

- Fixed import paths in useKernel.ts to use specific module paths for better tree-shaking
- Removed unnecessary type assertions in useKernel.test.ts, using proper mock types
- Added comment referencing shared global type definition in resource-hooks.ts
- Fixed resource-hooks.test.ts mock to return undefined instead of null
- Fixed TypeScript project references configuration:
  - Removed incompatible 'noEmit: true' from test configs (kernel & ui packages)
  - Added packages/ui/tsconfig.tests.json reference to root tsconfig.json
  - Added global types to UI test config include paths
- All tests passing: 947 total (945 passed, 2 skipped)
- All typecheck validations passing
pipewrk added a commit that referenced this pull request Nov 8, 2025
- Refactor complex type assertion chain in ensureDispatch()
- Extract invokeMethod after type guard for cleaner code flow
- Add explanatory comment for generic type casting responsibility
- Document intentional primitive throw in test case for error normalization

Addresses Copilot PR feedback #70 comments 5-6
pipewrk added a commit that referenced this pull request Nov 8, 2025
- Add module-level queue for resources created before UI bundle loads
- Kernel side: Queue resources and expose __WP_KERNEL_UI_PROCESS_PENDING_RESOURCES__
- UI side: Process pending queue when resource-hooks.ts module loads
- Add global type definition for process function
- Fixes timing issue where resources defined before UI never get React hooks

Addresses P1 review comment from PR #70
pipewrk added a commit that referenced this pull request Nov 8, 2025
All Review Comments Resolved
- Fixed import path issues (relative and absolute paths)
- Improved type assertions with detailed explanatory comments
- Enhanced JSDoc documentation for all new functionality
- Fixed tsconfig test paths and configurations
- Resolved resource hook timing issue with queuing mechanism
- Fixed queue cancellation bug using cancellation token

Comprehensive JSDoc Documentation
- Added module-level documentation for resource-hooks.ts
- Documented lazy binding and pending resource queue system
- Enhanced type assertions with detailed explanations
- Added comments for global hook registration
- Documented WordPress data store integration patterns

Expanded Test Coverage (89.73 percent branches)
Added 50 plus new tests for uncovered branches:
- resource-hooks.test.ts: SSR handling, pending queue processing
- useAction.test.tsx: error paths, concurrency modes, cancellation
- useVisiblePrefetch.test.tsx: SSR handling, margin parsing, observer edge cases
- useHoverPrefetch.test.tsx: unmount cancellation, listener cleanup
- useKernel.test.tsx: middleware handling and cleanup
- usePolicy.test.tsx: promise rejection, runtime errors, success scenarios

Bug Fixes
- Fixed queue cancellation logic with queueCancelledRef
- Implemented resource hook lazy binding with pending queue
- Corrected non-null assertions in useVisiblePrefetch
- Added type guard for WordPress data store dispatch
- Improved error normalization in useAction hook

Coverage Improvements
- Overall: 97.00 percent statements, 89.73 percent branches, 98.01 percent functions
- All UI hooks meet or exceed branch coverage thresholds
- Comprehensive edge case testing, no regressions

All tests passing (970 of 972), all type checks green.

Refs: #70

Refs: #70
pipewrk added a commit that referenced this pull request Nov 8, 2025
Sprint 5: Bindings & Interactivity — migrate React hooks to UI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants