Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort saving if a file cannot be saved #16900

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

JasonWeill
Copy link
Contributor

References

Fixes jupyterlab/jupyter-collaboration#364.

Code changes

Aborts saving if the canSave property of the context is false. This is false when the context's model is in collaborative mode.

User-facing changes

When the user presses CTRL+S or +S with Jupyter Collaboration installed, the save command does nothing, and does not cause an error dialog to appear. Without Jupyter Collaboration installed, the command works as it did before.

Backwards-incompatible changes

None.

@JasonWeill JasonWeill added the bug label Oct 29, 2024
Copy link

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

Comment on lines 599 to 604
if (!this.canSave) {
// File cannot be saved.
return Promise.reject();
}
Copy link

Choose a reason for hiding this comment

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

Just for fun, I asked Claude to review this and it reverted with this suggestion:

if (!this.canSave) {
    // File cannot be saved.
    return Promise.reject(new Error('File cannot be saved')); // Add error message
}       

Feel free to ignore Claude! Else it all LGTM.

@jtpio jtpio added this to the 4.3.x milestone Oct 30, 2024
@jtpio
Copy link
Member

jtpio commented Oct 30, 2024

Thanks @JasonWeill for looking into this 👍

The test failures appear to be related though:

image

Comment on lines +599 to +604
if (!this.canSave) {
// File cannot be saved. The "save" command is disabled in the UI,
// but if the user tries to save anyway, act as though it succeeded.
this._saveState.emit('completed');
return Promise.resolve();
}
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to consider what effect it has on the logic for updating the model hash (which is needed to prevent spurious "File Changed" dialogs). This condition prevents updating contentHash as it is performed in _maybeSave method and this condition prevents ever reaching it. I hope this would not be a problem for RTC because it now uses fileChanged signal to propagate new contentHash since:

I also think that it would not make the situation worse for other drives either as in that case they would not update the hash as they could not save the content.

I think that all we need to do is document the side-effects when saving and when saving is skipped, especially if we are going to emit saveState even if the save did not happen.

@krassowski
Copy link
Member

It might be good to document what happens on save (what events are emitted depending on whether save is supported or not) in https://jupyterlab.readthedocs.io/en/latest/extension/documents.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ctrl-S is not disabled
4 participants