Skip to content

Commit cec91d3

Browse files
committed
fix: fix default metadata logic
1 parent e099928 commit cec91d3

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/notebooks/deepnote/converters/inputConverters.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,35 @@ export abstract class BaseInputBlockConverter<T extends z.ZodObject> implements
2727
* Helper method to update block metadata with common logic.
2828
* Clears block.content, parses schema, deletes DEEPNOTE_VSCODE_RAW_CONTENT_KEY,
2929
* and merges metadata with updates.
30+
*
31+
* If metadata is missing or invalid, applies default config.
32+
* Otherwise, preserves existing metadata and only applies updates.
3033
*/
3134
protected updateBlockMetadata(block: DeepnoteBlock, updates: Partial<z.infer<T>>): void {
3235
block.content = '';
3336

34-
const existingMetadata = this.schema().safeParse(block.metadata);
35-
const baseMetadata = existingMetadata.success ? existingMetadata.data : this.defaultConfig();
36-
3737
if (block.metadata != null) {
3838
delete block.metadata[DEEPNOTE_VSCODE_RAW_CONTENT_KEY];
3939
}
4040

41-
block.metadata = {
42-
...(block.metadata ?? {}),
43-
...baseMetadata,
44-
...updates
45-
};
41+
// Check if existing metadata is valid
42+
const existingMetadata = this.schema().safeParse(block.metadata);
43+
const hasValidMetadata =
44+
existingMetadata.success && block.metadata != null && Object.keys(block.metadata).length > 0;
45+
46+
if (hasValidMetadata) {
47+
// Preserve existing metadata and only apply updates
48+
block.metadata = {
49+
...(block.metadata ?? {}),
50+
...updates
51+
};
52+
} else {
53+
// Apply defaults when metadata is missing or invalid
54+
block.metadata = {
55+
...this.defaultConfig(),
56+
...updates
57+
};
58+
}
4659
}
4760

4861
applyChangesToBlock(block: DeepnoteBlock, _cell: NotebookCellData): void {

0 commit comments

Comments
 (0)