Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions news/2 Fixes/13981.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Backup on custom editors is being ignored.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export class NativeEditorStorage implements INotebookStorage {
// Attempt to read the contents if a viable file
const contents = NativeEditorStorage.isUntitledFile(file) ? possibleContents : await this.fs.readFile(file);

const skipDirtyContents = typeof options === 'boolean' ? options : !!options;
const skipDirtyContents = typeof options === 'boolean' ? options : !options || options.length === 0;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Root cause of the problem was the !!options was the opposite of what we wanted. This would turn an options into a true, whereas we really wanted any options to turn it into a false.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Aahg, the problem was options was an empty array.

@IanMatthewHuff Ian Huff (IanMatthewHuff) Sep 17, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not going to lie. I find lines 279 - 282 really hard to read.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah that's really why this bug happened. The skipDirtyContents and the backupId are both confusing. I think it would have been better to just add another argument to the function instead of having the overload.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel unclean just reading the function signature. I guess it's ok. Maybe we could distinctly split on if the options is a bool or a string and put it in a local variable name that actually makes sense?

if (typeof options === 'boolean') {
// assign to skipDirtyContents
} else if (typeof options === 'string') {
// assign to backupId
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I agree, Ian Huff (@IanMatthewHuff) suggestion will improve readability significantly

// Use backupId provided, else use static storage key.
const backupId =
typeof options === 'string' ? options : skipDirtyContents ? undefined : this.getStaticStorageKey(file);
Expand Down