fix: skip undefined tune data when a tune is in its default state - #3020
fix: skip undefined tune data when a tune is in its default state#3020Hyhyhyyy wants to merge 6 commits into
Conversation
|
Add corresponded test cases |
|
Thanks @neSpecc — addressed both points:
Let me know if you'd like the test shaped differently. |
There was a problem hiding this comment.
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
undefinedtune 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.
|
|
||
| ### 2.31.6 | ||
|
|
||
| - `Fix` - Skip undefined block tune data when a tune's `save()` returns `undefined` (tune in default state) (#3020) |
|
Updated the changelog entry to use the repository’s standard PR reference format: instead of . |
|
|
||
| ### 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) |
There was a problem hiding this comment.
let's move it under 2.31.7 and update a patch version in package.json, please
|
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. |
Summary
Closes #1683.
When a Block Tune's
save()returnsundefined(i.e. the tune is in its default state and has nothing to persist), the value was still written totunesData[name]. This leaves an explicitundefinedentry 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:
Changes
src/components/block/index.ts: skip storing a tune's data whensave()returnsundefined.Notes
The
BlockTune.save()type isBlockTuneData, but in practice a tune may intentionally returnundefinedto signal "no data / default state" (as described in the issue). The localas BlockTuneData | undefinedcast keeps the type checker happy while allowing the runtime guard.How to test
save()returnsundefinedin its default state.undefinedvalue.