feat(react): implement useInteractionTrace hook with pre-typed API#14
Merged
Conversation
c43d3ef to
4dc5271
Compare
fb99e1b to
f640248
Compare
There was a problem hiding this comment.
This PR introduces a useInteractionTrace React hook, offering a declarative and type-safe way to sign interaction traces on component mount, complete with a withTypes() pattern for enhanced compile-time safety. This feature improves the developer experience by providing robust interaction tracing, and no issues were flagged during the review.
Add React 19.2.4 to devDependencies for testing React hooks. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add useInteractionTrace hook that signs traces on component mount - Support .withTypes<TDefs>() for compile-time type safety - Include SSR guard (no-op when window is undefined) - Extract shared TraceDefinitions types to src/trace-definitions.mts - Add comprehensive tests including type inference validation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…race tests - Replace inline PerformanceObserver mock with createPerformanceObserverMock and createMockObserverRegistry from test-utils/performance-mocks - Add createPerformanceMock to properly handle performance.mark/measure when using vi.useFakeTimers() (HappyDOM breaks when performance.now is faked) - Add vi.runOnlyPendingTimers() before vi.useRealTimers() in all test suites per testing-library best practices to flush pending timers before cleanup - Simplify test assertions using observerRegistry.triggerCallback() This makes the React hook tests consistent with the core test files and reduces code duplication by ~40 lines. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
66b57af to
c8a8e89
Compare
The untyped API is a first-class option for users who don't need type enforcement, not a deprecated pattern. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Bloomca
approved these changes
Feb 5, 2026
Bloomca
left a comment
There was a problem hiding this comment.
I am not sure how to test it, but the code looks good 👍
Member
Author
|
@Bloomca just something like this to verify type checking works should be enough:
|
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.

This PR adds a React hook
useInteractionTracethat provides a declarative way to sign interaction traces when components mount. It follows the samewithTypes()pattern assignInteractionTracefor compile-time type safety.Stacked on top of #11
Documentation updates: #17
Example
Test Plan
To verify the type safety works:
Create a pre-typed hook:
Verify TypeScript catches errors:
useTrace('typo trace', ...))useTrace('test trace', { wrong: 123 }))useTrace('test trace', {}))Verify autocomplete suggests
'test trace'when typing the first argument