Bug Report: Autosave on Every Keystroke Exceeds Supabase Free-Tier Write Limits
Description
The document editor triggers an autosave to Supabase on every onChange event
from the text editor component : effectively on every keystroke. A user typing
at 60 WPM generates approximately 300 keystrokes per minute, each triggering
a separate Supabase UPDATE call. The Supabase free tier allows 500MB database
egress and 2 million rows read/written per month. A single active user typing
for one hour exhausts a significant fraction of the monthly write quota.
Steps to Reproduce
- Open the Supabase dashboard and navigate to Database > Logs.
- Start typing in the Draftdeckai document editor.
- Observe a new
UPDATE documents SET ... query for each keystroke.
- After 1 minute of typing, check that ~300 write operations have been logged.
Root Cause
The onChange callback calls supabase.from('documents').update(...) directly
without debouncing. No minimum interval is enforced between saves.
Impact
Heavy users exhaust the Supabase free-tier write quota within days, causing
the database to return errors and making the editor non-functional until the
quota resets.
Proposed Fix
Debounce the autosave call with a 2-second delay:
const debouncedSave = useMemo(
() => debounce(async (content: string) => {
await supabase.from("documents").update({ content }).eq("id", docId);
}, 2000),
[docId]
);
// In editor onChange:
onChange={(value) => {
setContent(value);
debouncedSave(value);
}}
Also add a visual "Saving..." indicator that clears to "Saved" after the
debounced call completes.
Bug Report: Autosave on Every Keystroke Exceeds Supabase Free-Tier Write Limits
Description
The document editor triggers an autosave to Supabase on every
onChangeeventfrom the text editor component : effectively on every keystroke. A user typing
at 60 WPM generates approximately 300 keystrokes per minute, each triggering
a separate Supabase
UPDATEcall. The Supabase free tier allows 500MB databaseegress and 2 million rows read/written per month. A single active user typing
for one hour exhausts a significant fraction of the monthly write quota.
Steps to Reproduce
UPDATE documents SET ...query for each keystroke.Root Cause
The
onChangecallback callssupabase.from('documents').update(...)directlywithout debouncing. No minimum interval is enforced between saves.
Impact
Heavy users exhaust the Supabase free-tier write quota within days, causing
the database to return errors and making the editor non-functional until the
quota resets.
Proposed Fix
Debounce the autosave call with a 2-second delay:
Also add a visual "Saving..." indicator that clears to "Saved" after the
debounced call completes.