Skip to content

fix: skip undefined tune data when a tune is in its default state - #3020

Open
Hyhyhyyy wants to merge 6 commits into
codex-team:nextfrom
Hyhyhyyy:fix/skip-undefined-tune-data
Open

fix: skip undefined tune data when a tune is in its default state#3020
Hyhyhyyy wants to merge 6 commits into
codex-team:nextfrom
Hyhyhyyy:fix/skip-undefined-tune-data

Conversation

@Hyhyhyyy

Copy link
Copy Markdown

Summary

Closes #1683.

When a Block Tune's save() returns undefined (i.e. the tune is in its default state and has nothing to persist), the value was still written to tunesData[name]. This leaves an explicit undefined entry in the saved tunes object, which then gets carried through load/save cycles.

This guards the assignment so that only defined tune data is stored:

const tuneData = tune.save() as BlockTuneData | undefined;

if (tuneData !== undefined) {
  tunesData[name] = tuneData;
}

Changes

  • src/components/block/index.ts: skip storing a tune's data when save() returns undefined.

Notes

The BlockTune.save() type is BlockTuneData, but in practice a tune may intentionally return undefined to signal "no data / default state" (as described in the issue). The local as BlockTuneData | undefined cast keeps the type checker happy while allowing the runtime guard.

How to test

  1. Create a block tune whose save() returns undefined in its default state.
  2. Save the block and inspect the output JSON — the tune key should no longer appear with an undefined value.

@neSpecc neSpecc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please, update a changelog

@neSpecc

neSpecc commented Aug 19, 2026

Copy link
Copy Markdown
Member

Add corresponded test cases

@Hyhyhyyy

Copy link
Copy Markdown
Author

Thanks @neSpecc — addressed both points:

  • Added test cases in test/cypress/tests/api/tunes.cy.ts: one tune whose save() returns undefined (must be omitted from saved data) and a control tune returning a real value (must still be persisted). The case fails against the old behavior and passes with the fix.
  • Added a changelog entry under 2.31.6.

Let me know if you'd like the test shaped differently.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Block Tune serialization so that when a tune’s save() returns undefined (representing a default/no-data state), the tune entry is omitted from the saved tunes object rather than being written as an explicit undefined value (which can persist across in-memory load/save cycles).

Changes:

  • Guard tunesData[name] = ... so only defined tune data is stored.
  • Add a Cypress test that verifies undefined tune data is omitted while other tune data is still persisted.
  • Document the fix in the changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/cypress/tests/api/tunes.cy.ts Adds an e2e test to ensure save() returning undefined does not produce a tunes entry.
src/components/block/index.ts Skips writing tune data when tune.save() returns undefined.
docs/CHANGELOG.md Notes the fix in the 2.31.6 changelog.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/CHANGELOG.md Outdated

### 2.31.6

- `Fix` - Skip undefined block tune data when a tune's `save()` returns `undefined` (tune in default state) (#3020)
@Hyhyhyyy

Copy link
Copy Markdown
Author

Updated the changelog entry to use the repository’s standard PR reference format: instead of .

Comment thread docs/CHANGELOG.md Outdated

### 2.31.6

- `Fix` - Skip undefined block tune data when a tune's `save()` returns `undefined` (tune in default state) [#3020](https://github.com/codex-team/editor.js/pull/3020)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's move it under 2.31.7 and update a patch version in package.json, please

@Hyhyhyyy

Copy link
Copy Markdown
Author

Done. Moved the fix entry from 2.31.6 to a new 2.31.7 section and bumped the package version to 2.31.7.

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.

BlockTunes API should remove "undefined" tune data

3 participants