Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion jupyter_server_documents/outputs/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def _process_loaded_no_placeholders(self, file_id: str, nb: dict) -> dict:
cell['outputs'] = processed_outputs
return nb

def process_saving_notebook(self, nb: dict) -> dict:
def process_saving_notebook(self, nb: dict, file_id: str) -> dict:
"""Process a notebook before saving to disk.

This method is called when the yroom_file_api saves notebooks.
Expand All @@ -311,6 +311,7 @@ def process_saving_notebook(self, nb: dict) -> dict:

Args:
nb (dict): The notebook dict
file_id (str): The file identifier

Returns:
dict: The modified file data with placeholder_outputs set to True
Expand All @@ -326,6 +327,12 @@ def process_saving_notebook(self, nb: dict) -> dict:
# Clear outputs for all code cells, as they are saved to disk
for cell in nb.get('cells', []):
if cell.get('cell_type') == 'code':
# If outputs is already an empty list, call clear for this cell
if cell.get('outputs') == []:
cell_id = cell.get('id')
if cell_id:
self.clear(file_id, cell_id)

cell['outputs'] = []

return nb
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server_documents/rooms/yroom_file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ async def save(self, jupyter_ydoc: YBaseDoc):
self._save_scheduled = False

if self.file_type == "notebook":
content = self.outputs_manager.process_saving_notebook(content)
content = self.outputs_manager.process_saving_notebook(content, self.file_id)

# Save the YDoc via the ContentsManager
async with self._content_lock:
Expand Down
Loading