-
-
Notifications
You must be signed in to change notification settings - Fork 153
fix: repl: Always select a file when calling workspace.set() #1297
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
Conversation
This might fix sveltejs#1287, sveltejs#868, etc.
@cmcaine is attempting to deploy a commit to the Svelte Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
The way to test the bug is to go to the tutorial, try selecting some files and then click forward and back and see what happens. Navigating between most of the tutorials now seems to work correctly, but going here, selecting Canvas.svelte and then clicking the next arrow shows me a JSON file for some reason. |
const matching_file = selected && files.find((file) => is_file(file) && file.name === selected); | ||
if (matching_file) { | ||
this.#select(matching_file as File); | ||
} else { | ||
this.#select(first); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we trust the types (selected
can't be undefined because this.#current
is never nullish
), this can be further simplified to:
const matching_file = selected && files.find((file) => is_file(file) && file.name === selected); | |
if (matching_file) { | |
this.#select(matching_file as File); | |
} else { | |
this.#select(first); | |
} | |
const file = files.find((file) => is_file(file) && file.name === selected) as File; | |
this.#select(file ?? first); |
and the ?
in this method's default argument can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we trust that this.#current
is never nullish? It is initialised like this: #current = $state.raw() as File
(which is obviously a lie) and set()
is called in the constructor before any obvious updates to this.#current
.
I think maybe the type of this.#current
should be updated to File | undefined
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, you're right, I completely missed the initialization and was only looking at assignments to #current
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much!
Thanks for reviewing and accepting this PR! |
This might fix #1287, #868, etc.