Skip to content

Fix RangeError in announcement post notifications#3708

Merged
todwadd merged 1 commit intomainfrom
fix/bulk-insert-announcement-notifications
Mar 6, 2026
Merged

Fix RangeError in announcement post notifications#3708
todwadd merged 1 commit intomainfrom
fix/bulk-insert-announcement-notifications

Conversation

@todwadd
Copy link
Collaborator

@todwadd todwadd commented Mar 6, 2026

Announcement posts notify all users (100k+). The bulkInsert function tried to build a single INSERT query for all rows, exceeding JS's max string length and crashing with "RangeError: Invalid string length".

Changes:

  • bulkInsert() now chunks values into batches of 1000 rows to avoid generating queries that exceed the JS string length limit
  • Hoist richTextToString() call out of the per-user loop (was being called 100k+ times redundantly for announcements)
  • Truncate announcement sourceText to 200 chars (was unbounded, unlike the non-announcement path)

Error from logs:
RangeError: Invalid string length at Array.join () at Object.insert (pg-promise/lib/helpers/methods/insert.js:141:12) at bulkInsertQuery (backend/shared/src/supabase/utils.ts:40:29)

@vercel
Copy link

vercel bot commented Mar 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dev Ready Ready Preview, Comment Mar 6, 2026 1:10am
prod Ready Ready Preview, Comment Mar 6, 2026 1:10am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Mar 6, 2026 1:10am

Request Review

Announcement posts notify all users (100k+). The bulkInsert function
tried to build a single INSERT query for all rows, exceeding JS's max
string length and crashing with "RangeError: Invalid string length".

Changes:
- bulkInsert() now chunks values into batches of 1000 rows to avoid
  generating queries that exceed the JS string length limit
- Hoist richTextToString() call out of the per-user loop (was being
  called 100k+ times redundantly for announcements)
- Truncate announcement sourceText to 200 chars (was unbounded, unlike
  the non-announcement path)

Error from logs:
  RangeError: Invalid string length
    at Array.join (<anonymous>)
    at Object.insert (pg-promise/lib/helpers/methods/insert.js:141:12)
    at bulkInsertQuery (backend/shared/src/supabase/utils.ts:40:29)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@todwadd todwadd force-pushed the fix/bulk-insert-announcement-notifications branch from a44f8b1 to d7e6c1c Compare March 6, 2026 01:04
Copy link
Collaborator

@IanPhilips IanPhilips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@todwadd todwadd merged commit 1790000 into main Mar 6, 2026
3 of 5 checks passed
@todwadd todwadd deleted the fix/bulk-insert-announcement-notifications branch March 6, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants