-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(checkout): Reactive but debounced volume sliders #106525
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,14 +48,17 @@ function ReserveAdditionalVolume({ | |
| }).price > 0 | ||
| ) | ||
| ); | ||
| const [reserved, setReserved] = useState<Partial<Record<DataCategory, number>>>( | ||
| formData.reserved | ||
| ); | ||
| const reservedVolumeTotal = useMemo(() => { | ||
| return Object.entries(formData.reserved).reduce((acc, [category, value]) => { | ||
| return Object.entries(reserved).reduce((acc, [category, value]) => { | ||
| const bucket = activePlan.planCategories?.[category as DataCategory]?.find( | ||
| b => b.events === value | ||
| ); | ||
| return acc + (bucket?.price ?? 0); | ||
| }, 0); | ||
| }, [formData.reserved, activePlan]); | ||
| }, [reserved, activePlan]); | ||
|
|
||
| const handleReservedChange = useCallback( | ||
| (value: number, category: DataCategory) => { | ||
|
|
@@ -137,9 +140,12 @@ function ReserveAdditionalVolume({ | |
| activePlan={activePlan} | ||
| organization={organization} | ||
| onUpdate={onUpdate} | ||
| formData={formData} | ||
| subscription={subscription} | ||
| onReservedChange={debouncedReservedChange} | ||
| onReservedChange={(newReserved, category) => { | ||
| setReserved(prev => ({...prev, [category]: newReserved})); | ||
| debouncedReservedChange(newReserved, category); | ||
| }} | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rapid multi-slider changes cause UI/data desyncMedium Severity When a user rapidly adjusts multiple different category sliders within 300ms, lodash Additional Locations (1) |
||
| currentSliderValues={reserved} | ||
| /> | ||
| </Stack> | ||
| )} | ||
|
|
||
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.
Bug: The component's local
reservedstate does not sync with theformData.reservedprop, causing stale UI data and incorrect price calculations when the plan changes.Severity: MEDIUM
Suggested Fix
Add a
useEffecthook in theReserveAdditionalVolumecomponent to update the localreservedstate whenever theformData.reservedprop changes. For example:useEffect(() => { setReserved(formData.reserved); }, [formData.reserved]);Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.