generated from darkroomengineering/satus
-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: modernize hooks with React 18+ patterns #10
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
Open
arzafran
wants to merge
9
commits into
main
Choose a base branch
from
modernization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BREAKING CHANGES: - Minimum React version bumped from 17 to 18 - Removed `deps` parameter from useResizeObserver, useIntersectionObserver, useLazyState, useRect - useMediaQuery now returns boolean instead of boolean | undefined New features: - useSyncExternalStore for concurrent-safe subscriptions in useWindowSize, useMediaQuery, useRect - Selective hooks: useWindowWidth, useWindowHeight, useWindowDpr - SSR safety checks in all hooks - Improved TypeScript types (removed @ts-ignore, proper generics) Other changes: - Migrated from pnpm to bun - Removed useMemo from useObjectFit (pure computation) - Cleaned up dead code in use-debounce - Added MIGRATION.md documentation
Consolidations: - Extract createDebounceConfig to shared/debounce-config.ts - Extract useLatestCallback to shared/use-latest-callback.ts - Extract LazyReturn types to shared/types.ts - Add try/finally for DOM style restoration in useRect CI updates: - Upgrade actions/checkout and actions/setup-node to v4 - Upgrade Node.js from 16 to 22 (current LTS) - Replace pnpm with bun in publish workflow Also fixes: - Update playground to use new useDebouncedCallback API (2 args)
- Replace old logo with new hamo mark across all pages - Rewrite React playground with interactive demos for all hooks - Add visual feedback for useWindowSize, useMediaQuery, useRect - Add resizable box for useResizeObserver demo - Add scroll-triggered demo for useIntersectionObserver - Add side-by-side comparison for useDebouncedState - Add render count tracking for useLazyState demo - Update homepage with hooks overview and navigation - Remove broken core.astro page - Apply consistent dark theme styling
- Remove eslint in favor of biome-only (matching satus) - Bump biome to 2.3.13 (matching satus) - Update biome.json with comprehensive lint rules from satus - Add lint, lint:fix, format, and check scripts - Update .vscode/settings.json for biome - Auto-fix import sorting and formatting - Add noop comments to satisfy noEmptyBlockStatements - Exclude .astro files from biome (unsupported syntax)
- Cache WindowSize object reference in useWindowSize - Cache primitive values for selective hooks (width, height, dpr) - Restore missing imports in Astro pages (removed by biome) - Only create new snapshot objects when values actually change Fixes: "The result of getSnapshot should be cached" React warning
- Make rect-box resizable so width/height values update on drag - Add "Add block above" button to demonstrate top value changes - Update copy from incorrect "scroll to see values" to accurate description - Remove outdated deps parameter from useRect README (removed in v2.0) - Fix setDebounce reference in docs - Add .tldr to gitignore
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR modernizes hamo to leverage React 18+ features for better performance, concurrent rendering safety, and developer experience.
Key Changes
useSyncExternalStoreadoption - Window size, media query, and rect hooks now use React 18's concurrent-safe subscription APIuseWindowWidth,useWindowHeight,useWindowDprhooks that only re-render when their specific value changes@ts-ignore, proper generic inference for lazy modepackages/react/src/shared/Breaking Changes
>=17.0.0>=18.0.0depsparameteruseResizeObserver,useIntersectionObserver,useLazyState,useRectuseMediaQueryreturnboolean | undefinedbooleanMigration for
depsremovalIf you relied on the
depsarray:New Features
Selective Window Hooks
Avoid unnecessary re-renders by subscribing to only what you need:
SSR Fallback for Media Queries
Shared Utilities
Common patterns extracted to
packages/react/src/shared/:createDebounceConfig()useLatestCallback()LazyReturn<T, L>ObserverHookReturn<T, L>Technical Details
Why
useSyncExternalStore?From This Week in React:
getSnapshotreturns only what it needs, preventing over-renderinggetServerSnapshotprovides consistent server-side valuesHooks Updated
useWindowSizeuseSyncExternalStore, single state object instead of 3useStateuseWindowWidth/Height/DpruseMediaQueryuseSyncExternalStore, SSR fallback parameteruseResizeObserveruseIntersectionObserveruseRectuseSyncExternalStorefor emitter, try/finally for DOM safety, removed depsuseLazyStateuseObjectFituseMemo(pure computation)useDebouncedEffect/State/CallbackSecurity Improvements
try/finallyto sticky position manipulation inuseRect- ensures DOM styles are restored even if measurement throwsCI/CD Updates
Playground Overhaul
The playground has been completely rewritten with interactive demos for all hooks:
Updated branding with new hamo mark throughout.
Documentation Updates
depsparameter from useRect README (was removed in v2.0)setDebouncereference in useRect docsTest Plan
bun run build<StrictMode>Files Changed
References