-
Notifications
You must be signed in to change notification settings - Fork 1
release: 0.3.0 — React Hooks Migration & Resource API Refinements #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Sprint 5: Move hooks to @geekist/wp-kernel-ui This release completes the separation of React-specific code from the core kernel package, moving all hooks to @geekist/wp-kernel-ui while maintaining backward compatibility through runtime attachment. ## Breaking Changes - Removed `use` namespace from ResourceObject grouped API (use thin-flat API instead) - React hooks (useGet, useList, useAction, usePolicy, etc.) now require @geekist/wp-kernel-ui ## Features - Added React hooks package (@geekist/wp-kernel-ui) with full test coverage - Hooks attach to resources at runtime via globalThis bridge - New hooks: useAction, usePolicy, useHoverPrefetch, useVisiblePrefetch, useNextPagePrefetch - Enhanced prefetching capabilities with intersection observer support ## Bug Fixes - Fixed useSelect referential equality issue causing infinite re-renders - Fixed loading state logic: trust status='success' over hasFinishedResolution - Removed React code from kernel package (now framework-agnostic) - Updated resource hooks to use primitive returns for proper memoization ## Documentation - Added comprehensive guides for all new hooks - Updated API documentation with hook examples - Added prefetching guide with real-world patterns - Updated resource guides to reflect UI package integration ## Improvements - Refactored high-complexity functions with helper utilities - Added ESLint rules for code quality enforcement - Improved test coverage across all packages - Enhanced JSDoc comments throughout codebase ## Related - Closes #71 - Major milestone toward beta release Co-authored-by: Release Please <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Completes 0.3.0 release: fixes resource hook loading-state regression after moving React hooks into UI package, removes deprecated grouped use.* API in favor of thin-flat useGet / useList, and refactors validation, namespace detection, store reducer, and transport/event emission for clarity and modularity.
- Fixes infinite loading by trusting list status over
hasFinishedResolutionand memoizing hook selector results. - Removes grouped
resource.use.item()/list()API and updates docs/tests; broad type refactors (interfaces → type aliases) plus internal decomposition of large functions (namespace detection, policy/cache, actions). - Adds stricter lint rules & supporting dev deps; augments tests for loading edge cases.
Reviewed Changes
Copilot reviewed 53 out of 107 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ui/src/hooks/usePolicy.ts | Reordered conditional to equivalent positive form for policy runtime presence. |
| packages/ui/src/hooks/useAction.ts | Refactored dispatch resolution into smaller helpers (env check, registry, store registration, invoke wrapper). |
| packages/ui/src/hooks/resource-hooks.ts | Centralized loading logic into helper functions; simplified selector return objects. |
| packages/ui/src/hooks/internal/useStableCallback.ts | Expanded internal documentation for hook utilities. |
| packages/ui/src/hooks/tests/resource-hooks.test.ts | Added tests covering new loading-state semantics (idle unresolved, resolving after success). |
| packages/kernel/src/resource/validation.ts | Modularized config validation with reusable helpers and shared constants. |
| packages/kernel/src/resource/types.ts | Converted many interfaces to type aliases; removed grouped use hook namespace. |
| packages/kernel/src/resource/store.ts | Refactored reducer into discrete pure helpers with action handler map. |
| packages/kernel/src/resource/grouped-api.ts | Removed createUseGetter (deprecated grouped hooks). |
| packages/kernel/src/resource/define.ts | Removed grouped use getter; minor window access simplifications. |
| packages/kernel/src/resource/cache.ts | Interface → type alias changes and invalidate options alias. |
| packages/kernel/src/resource/tests/* | Updated tests removing grouped use expectations. |
| packages/kernel/src/reporter/types.ts | Interfaces → type aliases for reporter contracts. |
| packages/kernel/src/policy/* | Refactors: split emission paths (hooks, broadcast, bridge), granular cache broadcast message types. |
| packages/kernel/src/namespace/detect.ts | Large refactor: decomposed detection pipeline, candidate evaluation; added helpers & internal docs. |
| packages/kernel/src/namespace/tests/detect.test.ts | Adjusted test expectations for new fallback sanitization behavior. |
| packages/kernel/src/http/* | Introduced helper emit functions; refactored api-fetch resolution and event emission. |
| packages/kernel/src/error/* | Interfaces → type aliases. |
| packages/kernel/src/data/plugins/events.ts | Type alias conversions and middleware typing tweak. |
| packages/kernel/src/actions/* | Type alias conversions; refactored lifecycle emission into smaller functions. |
| packages/e2e-utils/src/types.ts | Interfaces → type aliases for test utilities. |
| packages/e2e-utils/src/createKernelUtils.ts | Added secure selector parsing & path extraction for store helpers. |
| packages/e2e-utils/src/tests/createStoreHelper.test.ts | Updated tests to reflect restricted selector capability. |
| app/showcase/* | Updated props & inputs from interfaces to type aliases; minor logic tweak in job-create cleanup. |
| docs/* | Updated documentation to remove grouped use.* API and promote thin-flat hooks from UI package. |
| package.json | Added stricter lint/test scripts and dev dependencies (lint plugins, code mods). |
| eslint.config.js | Added import/unicorn/sonarjs/early-return plugins and complexity/depth rules (disabled for tests). |
| .release-please-manifest.json | Bumped package versions to 0.3.0. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
- Fix error message handling: getItemError returns string, not Error object - Update WordPressStoreSelector type to match actual store behavior - Preserve original namespace in fallback for debugging/introspection - Add regression test for WordPress quirk: status='success' with hasFinishedResolution=false - Fix test mocks to return undefined instead of null for error values Addresses review comments from PR #73
There was a problem hiding this 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 53 out of 107 changed files in this pull request and generated 5 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Co-authored-by: Copilot <[email protected]> Signed-off-by: Jason Joseph Nathan <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Jason Joseph Nathan <[email protected]>
- Fix resetState() to match original INVALIDATE_ALL behavior * Remove ...initialState spread that incorrectly preserved custom fields * Add comment clarifying intentional clearing of all state * Addresses review comment about behavior change - Document null check pattern in fetch helper functions * Add JSDoc explaining why each helper checks hooks independently * Addresses nitpick review comment about repetitive null checks * Current pattern maintains isolation and testability - Auto-format code per linter rules
|
Re: Helper function null checks (nitpick) The design choice is now documented! See the JSDoc comment on /**
* Emit request event via hooks.
* Each helper performs its own null check for isolation and testability,
* rather than relying on an early guard in the caller.
*/Each helper ( Since this is architecture by design (not oversight), I've kept the current implementation with documentation rather than consolidating guards. 👍 |
- Fix error message handling: getItemError returns string, not Error object - Update WordPressStoreSelector type to match actual store behavior - Preserve original namespace in fallback for debugging/introspection - Add regression test for WordPress quirk: status='success' with hasFinishedResolution=false - Fix test mocks to return undefined instead of null for error values Addresses review comments from PR #73
release: 0.3.0 — React Hooks Migration & Resource API Refinements
Summary
Release 0.3.0: React Hooks Migration to UI Package & Resource API Refinements
Sprint: 5 (Bindings & Interactivity) + Bug fixes
Scope: resource · ui · e2e-utils
Links
Why
The original PR #71 successfully moved React hooks from
@geekist/wp-kernelto@geekist/wp-kernel-ui, but introduced a critical bug in the refactored loading state logic. This PR completes the release with the following fixes:computeListStatefunction was creating new objects on every call, breakinguseSelect's referential equality checks and causing infinite loading statesuse.*namespace from grouped API (keeping directuseGet/useListas preferred thin-flat API)@geekist/wp-kernel-uiWhat
use.*grouped API namespace (redundant with thin-flatuseGet/useList)shouldShowLoadingStateto not checkhasFinishedResolutionwhen status is already resolvedHow
Loading State Fix:
The bug was in
shouldShowLoadingState- it checkedhasFinishedResolution === falseeven whenstatus === 'success'. WordPress's data store has a quirk wherehasFinishedResolutioncan return false even after status is success.Solution: Trust the explicit status value (
'success'or'error') and only checkhasFinishedResolutionwhen status is'idle'.Refactoring Fix:
Changed helper functions to return primitives (booleans) instead of objects, allowing
useSelectto properly memoize the final object created in the callback.Trade-offs:
use.*grouped API - developers should useresource.useGet()instead ofresource.use.item()Testing
How to verify locally:
pnpm install && pnpm buildpnpm wp:startTest Matrix
pnpm test) - 969 passed, 2 skippedpnpm e2e) - All passing including "renders jobs and supports search filtering"pnpm typecheck) - Cleanpnpm typecheck:tests) - CleanScreenshots / Recordings
Loading state now resolves correctly when data is available.
Breaking Changes
resource.use.item()andresource.use.list()from grouped APIresource.useGet()andresource.useList()instead (thin-flat API)Affected Packages
@geekist/wp-kernel- Removedusegrouped API namespace@geekist/wp-kernel-ui- Fixed resource hooks loading logic@geekist/wp-kernel-cli@geekist/wp-kernel-e2e-utilsRelease
Checklist
pnpm test) - 969 passedpnpm e2e) - All scenarios passingpnpm lint)pnpm typecheck,pnpm typecheck:tests)Note: This PR represents the complete 0.3.0 release that was partially merged in #71. The commit history includes the original migration work plus critical bug fixes discovered during integration testing.