-
-
Notifications
You must be signed in to change notification settings - Fork 7
perf: improve throttling with useThrottledDebounce hook #112
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
base: stable-opts
Are you sure you want to change the base?
Conversation
Port hybrid throttle+debounce pattern from streamdown: - Immediate update when throttle window has passed - Debounce for rapid changes within throttle window - Value-based hook instead of imperative callback pattern - Remove TimeoutState type (no longer needed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 386b9dc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Claude finished @AVGVSTVS96's task —— View job Claude finished @AVGVSTVS96's task —— View job Code Review: useThrottledDebounce HookI've completed a comprehensive review of the throttle-debounce performance improvements. Here's my assessment: ✅ Overall Assessment: Excellent ImplementationThis PR successfully modernizes throttling from imperative to reactive patterns with excellent architecture and thorough testing. 🎯 StrengthsClean Architecture & Design
API Compatibility
Implementation Quality
Code Simplification
Excellent Test Coverage
🔍 Technical Deep DiveNew useThrottledDebounce Hook (utils.ts:30-72)// Excellent hybrid approach:
if (timeSinceLastRun >= throttleMs) {
setProcessedValue(value); // Immediate update
lastRunTime.current = now;
} else {
timeoutRef.current = setTimeout(() => {
setProcessedValue(value); // Debounced update
lastRunTime.current = Date.now();
}, debounceMs);
}Why this is superior:
Changeset Quality
💡 Minor Suggestions1. Documentation EnhancementConsider adding JSDoc example to /**
* @example
* // Throttle search queries with 300ms throttle + 50ms debounce
* const throttledQuery = useThrottledDebounce(searchQuery, 300);
*/2. Consider Making debounceMs ConfigurableCurrently hardcoded at 50ms. Could be useful as an option: useThrottledDebounce(value, throttleMs, debounceMs = 50)3. Potential Race Condition Edge CaseIn const updateTime = Date.now();
lastRunTime.current = updateTime;🚀 Performance & Security
✅ Requirements Check
🏆 Recommendation: APPROVEThis is an exemplary refactoring that improves code quality, maintainability, and user experience while maintaining perfect backward compatibility. The hybrid throttle+debounce approach is particularly well-designed for the syntax highlighting use case. Special acknowledgment: The attribution to @haydenbleasel and streamdown demonstrates good open source practices. |
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
46c4c2c to
bf3790a
Compare
4976526 to
632a28d
Compare
632a28d to
5f25860
Compare
bf3790a to
b102fb6
Compare
b102fb6 to
e42ca23
Compare
5f25860 to
ecd57a5
Compare
ecd57a5 to
53a82f3
Compare
e42ca23 to
d0e73ac
Compare
53a82f3 to
644ec9c
Compare
d0e73ac to
25b7e45
Compare
644ec9c to
69c80e6
Compare
25b7e45 to
d6d355b
Compare
69c80e6 to
c5a4180
Compare
d6d355b to
386b9dc
Compare

This PR replaces the imperative
throttleHighlightingfunction with a reactiveuseThrottledDebouncehook.Acknowledgment
Implementation inspired by streamdown's
useThrottledDebouncehook, originally authored by @haydenbleasel.Changes
New hybrid throttle+debounce behavior:
Code simplification:
TimeoutStateinterfaceAPI
No breaking changes - public API remains identical:
delayoption still controls throttlingdelayis omitted/undefined)Test plan
useThrottledDebouncehook