Skip to content

fix: crash when saving a row with all empty values#751

Merged
theoephraim merged 3 commits intomainfrom
fix/empty-row-save-crash
Feb 14, 2026
Merged

fix: crash when saving a row with all empty values#751
theoephraim merged 3 commits intomainfrom
fix/empty-row-save-crash

Conversation

@theoephraim
Copy link
Copy Markdown
Owner

Summary

  • Fix crash when calling row.save() after clearing all values in a row — the Google Sheets API omits values from the response when all cells are empty, causing Cannot read properties of undefined (reading '0')
  • Fix inconsistency where empty cells could return undefined instead of '' — the API truncates trailing empty values from arrays, so row.get('trailingColumn') would return undefined instead of ''
  • Pad _rawData to always match header length with empty strings, both in the GoogleSpreadsheetRow constructor (covers getRows/addRows) and after save()

Incorporates #558, fixes #644

Test plan

  • Added test: saving a row with trailing empty values returns '' (not undefined)
  • Added test: trailing empty values persist correctly after re-fetching rows
  • Added test: clearing all values in a row via save() works without crashing
  • Added test: toObject() returns '' for cleared values (not undefined)
  • Added test: all-empty row persists correctly after re-fetching
  • All existing row tests still pass

🤖 Generated with Claude Code

The Google Sheets API omits `values` from the response when all cells
are empty, and truncates trailing empty cells. This caused a crash
on `row.save()` and inconsistent `undefined` vs `''` for empty cells.

Fix by padding `_rawData` to match header length with empty strings,
both in the constructor (covers getRows/addRows) and after save().

Fixes #558, closes #644

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 14, 2026

🦋 Changeset detected

Latest commit: 5262e8d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
google-spreadsheet Patch

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

theoephraim and others added 2 commits February 13, 2026 22:47
- Ensure empty cells in rows always return '' instead of undefined
- Move merge/unmerge tests from rows.test.ts to cells.test.ts where
  they belong, rewritten to use cell-based assertions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…r empty cells

Empty cells now consistently return '' after rawData padding normalization.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@theoephraim theoephraim merged commit fd12a3b into main Feb 14, 2026
1 of 2 checks passed
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.

Save a formula or any string which starts with "=" as a string using the cells-based interface

1 participant