Repository navigation
perf: resolve iOS routing on the first client-only render (useSyncExternalStore) - #44
Merged
Merged
Conversation
Merged
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
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.
Closes #39
What
useIOSNativeHaptics()now usesuseSyncExternalStore(noopSubscribe, isIOSWebKitWithoutVibration, () => false)instead ofuseState(false)+useEffect.createRoot, client navigation, lists added later): React reads the client snapshot directly, so iOS routing resolves on the first render and eachHapticTargetskips the post-mount routing update.false.renderToStringoutput is byte-for-byte unchanged, and hydration rendersfalsefirst, then resolves after hydration with no mismatch.Visible API change
On iOS,
useIOSNativeHaptics()now returnstrueon the first client-only render instead of after an effect. Hydrated renders still returnfalsefirst. This is documented as a Behavior change inCHANGELOG.md, in the package README, and in the docs (api.mdx,index.mdx). Because of it, the next release should be a pre-1.0 minor (0.3.0).Implemented with the Codex CLI on the shared box and verified by hand.
Benchmark (
npm run bench, same box, 3 interleaved pairs)Baseline is
mainat1ea44a1(already includes #42 and #43).1ea44a1The commit and render counts are deterministic. The timing rows aren't conclusive. Another agent's build was saturating the shared 8-core box during these runs (load average 13–18; main's iOS 1,000-instance mount measured 120–150 ms on a quieter box earlier today). The issue's 1-commit target assumed the old observer path. With #43's guarantee that no overlay is committed before the host is checked, the floor is 2 commits: render, then layout-phase host sync, before paint.
Verification
npm run lint,typecheck(ESM+CJS+DTS build),coverage(141 tests, 100% statements/branches/functions/lines on React 19 and React 18.3.1),size,pack:check, anddocs:checkall pass.createRootrender on iOS stubs returnstrueon the first render (renders === [true]).renderToStringnever readsnavigator(a throwing getter proves it) and its markup is byte-identical.hydrateRooton iOS stubs renders[false, true]with no recoverable errors and noconsole.error, and the switch appears after hydration.navigatoraccess, and the server snapshot is a constantfalse.Device-testing notes
These are simulated-browser numbers from Node 24 with production React and jsdom, using a stubbed iPhone/AppleWebKit
navigator. None were measured on physical devices, and no physical device was used. Physical iPhone/Android/iPadOS/VoiceOver certification is still tracked in #9.