Skip to content

Comments

fix(persister): restore MergeableChanges handling in extractChangedTables#3240

Merged
yujonglee merged 3 commits intomainfrom
fix-session-persister-mergeable-changes
Jan 20, 2026
Merged

fix(persister): restore MergeableChanges handling in extractChangedTables#3240
yujonglee merged 3 commits intomainfrom
fix-session-persister-mergeable-changes

Conversation

@yujonglee
Copy link
Contributor

@yujonglee yujonglee commented Jan 20, 2026

Summary

  • Fix session folder (sessions/*.md, _meta.json, etc.) not persisting since nightly.8 release (worked in nightly.7)
  • Restore MergeableChanges format handling in extractChangedTables()

Root Cause Analysis

Commit 64922dfba ("remove stamp repair that might cause dataloss") simplified extractChangedTables() too aggressively.

TinyBase sends changes in two different formats depending on the store type:

Format Structure When Used
Regular Changes [changedTables, changedValues, 1] Regular Store
MergeableChanges [[changedTables, hlc?], [changedValues, hlc?], 1] MergeableStore

The app uses a MergeableStore, which sends changes in format #2.

Before (nightly.7 - working)

const tablesOrStamp = changes[0];

// MergeableChanges: [[changedTables, hlc?], [changedValues, hlc?], 1]
if (Array.isArray(tablesOrStamp) && tablesOrStamp.length >= 1) {
  const tables = tablesOrStamp[0];
  if (tables && typeof tables === "object") {
    return unwrapMergeableTables(tables);
  }
  return null;
}

// Regular Changes: [changedTables, changedValues, 1]
if (tablesOrStamp && typeof tablesOrStamp === "object") {
  return tablesOrStamp as ChangedTables;
}

After (nightly.8 - broken)

const tables = changes[0];
if (tables && typeof tables === "object") {
  return tables as ChangedTables;
}

The Problem

With MergeableChanges, changes[0] is [changedTables, hlc?] (an array), not the tables object directly.

Since arrays are objects in JavaScript, typeof tables === "object" returns true, and the function returns [changedTables, hlc] instead of just changedTables.

When getChangedSessionIds receives this array:

  • It tries to access changedTables.sessions
  • Arrays don't have a .sessions property → returns undefined
  • Function thinks nothing changed → returns { operations: [] }
  • Nothing gets saved to disk

Test plan

  • All 304 persister tests pass
  • Added new test cases for MergeableChanges format
  • Manual verification with nightly build

Open with Devin

…bles

Commit 64922df removed MergeableChanges format handling from
extractChangedTables(), breaking session folder persistence for
MergeableStore users.

TinyBase sends changes in two formats:
- Regular Changes: [changedTables, changedValues, 1]
- MergeableChanges: [[changedTables, hlc?], [changedValues, hlc?], 1]

The simplified code didn't unwrap the inner array for MergeableChanges,
returning [changedTables, hlc] instead of changedTables. This caused
getChangedSessionIds to receive an array instead of an object, making
it think nothing changed and skipping all save operations.
@netlify
Copy link

netlify bot commented Jan 20, 2026

Deploy Preview for hyprnote-storybook canceled.

Name Link
🔨 Latest commit feb945f
🔍 Latest deploy log https://app.netlify.com/projects/hyprnote-storybook/deploys/696f55d41a728600083e8f69

@netlify
Copy link

netlify bot commented Jan 20, 2026

Deploy Preview for howto-fix-macos-audio-selection canceled.

Name Link
🔨 Latest commit feb945f
🔍 Latest deploy log https://app.netlify.com/projects/howto-fix-macos-audio-selection/deploys/696f55d499a08e00084fbc6e

@netlify
Copy link

netlify bot commented Jan 20, 2026

Deploy Preview for hyprnote canceled.

Name Link
🔨 Latest commit feb945f
🔍 Latest deploy log https://app.netlify.com/projects/hyprnote/deploys/696f55d4b3f6c3000829983c

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View issue and 2 additional flags in Devin Review.

Open in Devin Review

@yujonglee yujonglee merged commit 2b134d3 into main Jan 20, 2026
3 of 5 checks passed
@yujonglee yujonglee deleted the fix-session-persister-mergeable-changes branch January 20, 2026 10:15
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.

1 participant