fix: Avoid creating duplicate note blocks in Notion #468
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
As reported in #463, duplicate "Zotero Notes" blocks end up created when note content fails to sync. This occurred because block IDs were not saved into Zotero when a note failed to sync—even though the container blocks (i.e. "Zotero Notes" and the note heading) were indeed created in Notion. Without saving the block IDs into Zotero, the next sync attempt had nothing to reference and thus created additional container blocks.
Solution
We now save block IDs before attempting to sync the note content so that, if the note content fails to sync, we've already saved references to the block IDs to be used for the next sync attempt. Additionally, if we successfully create the "Zotero Notes" container but fail to create the note heading container, we still save the block ID of the "Zotero Notes" container.