Skip to content

Commit 922de38

Browse files
authored
fix(date-picker): eliminate infinite re-render crash on re-open with existing selection (#4609)
* docs(uploads): clarify QUOTA_EXEMPT_STORAGE_CONTEXTS logs entry in JSDoc * fix(date-picker): eliminate infinite re-render on re-open with existing selection The useEffect that syncs picker state on open had initialStart and initialEnd — Date objects computed on every render — in its dependency array. Because Object.is returns false for any two distinct Date instances, the effect fired on every render when open=true, calling setRangeStart/setRangeEnd and triggering another render, producing an infinite loop that crashed the page. Fix: compute start and end as local variables inside the effect and use the stable string props (props.startDate, props.endDate) as deps instead. Also removes the redundant typeof fileSize === 'number' guard in the multipart quota check — fileSize is z.number() (required) in the contract so it can never be undefined at that point. * refactor(date-picker): comprehensive cleanup and reliable crash fix The previous fix still had derived Date objects in useEffect deps. Object.is(new Date(), new Date()) === false, so any Date in deps causes the effect to run every render, reproducing the infinite loop on re-open with existing time selection. Key changes: - useEffect deps now use only stable primitives (startDate, endDate strings) and compute Date values inside the effect — eliminating the loop - Replace `rest as any` with a FlatDatePickerProps merged type for safe, typed destructuring across the discriminated union - Remove initialStart/initialEnd render-scope variables; compute inline or inside effects to keep derivation local to each use site - Callbacks use destructured props (onChange, onRangeChange, etc.) instead of props.x references - Remove verbose TSDoc on internal callbacks — names are self-documenting - Preserve all existing JSX structure and CalendarMonth logic unchanged
1 parent d0519c1 commit 922de38

3 files changed

Lines changed: 134 additions & 195 deletions

File tree

apps/sim/app/api/files/multipart/route.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,9 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
134134

135135
const config = getStorageConfig(storageContext)
136136

137-
if (
138-
!QUOTA_EXEMPT_STORAGE_CONTEXTS.has(context as StorageContext) &&
139-
typeof fileSize === 'number'
140-
) {
137+
if (!QUOTA_EXEMPT_STORAGE_CONTEXTS.has(context as StorageContext)) {
141138
const { checkStorageQuota } = await import('@/lib/billing/storage')
142-
const quotaCheck = await checkStorageQuota(userId, fileSize)
139+
const quotaCheck = await checkStorageQuota(userId, fileSize ?? 0)
143140
if (!quotaCheck.allowed) {
144141
return NextResponse.json(
145142
{ error: quotaCheck.error || 'Storage limit exceeded' },

0 commit comments

Comments
 (0)