-
Notifications
You must be signed in to change notification settings - Fork 25
chore: using simple objects in rpc api (to avoid snapshots) #1314
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
Moving to svelte 5, state objects are proxied. Normally that's an implementation detail, but when you try to pass the proxies through rpc they can't be cloned and result in errors. We could use $state.snapshot(build) every time we pass objects from the UI to the API, but we really shouldn't be passing whole objects to the backend and blindly trusting that the objects (including all properties) match what the backend knows anyway. This changes the three affected API functions to accept ids instead of objects, and the backend looks up the objects before acting. Although it's slightly more work on the backend, this is a better/more robust API, and also avoids the svelte 5 proxy issue. Fixes podman-desktop#1304. Signed-off-by: Tim deBoer <[email protected]>
packages/backend/src/api-impl.ts
Outdated
async checkVMLaunchPrereqs(buildId: string): Promise<string | undefined> { | ||
const build = this.history.getHistory().find(build => build.id === buildId); | ||
if (!build) { | ||
return Promise.reject(new Error(`Could not find build: ${buildId}`)); |
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.
question : why promise.rejectand not throw new Error ?
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.
Should be throw error, fixed in new commit.
packages/backend/src/api-impl.ts
Outdated
@@ -330,6 +344,7 @@ export class BootcApiImpl implements BootcApi { | |||
// this method is internal and meant to be used by the API implementation | |||
protected async notify(id: string, body: unknown = {}): Promise<void> { | |||
// Must pass in an empty body, if it is undefined this fails | |||
console.log('notify frontend: ' + id); |
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.
remove ?
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.
Removed.
Signed-off-by: Tim deBoer <[email protected]>
packages/backend/src/api-impl.ts
Outdated
const builds = buildIds | ||
.map(id => this.history.getHistory().find(build => build.id === id)) | ||
.filter(build => build) as BootcBuildInfo[]; |
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.
issue: since TypeScript 5.5 / microsoft/TypeScript#57465 the inferring is automatic on the filter so no need to add a cast to as BootcBuildInfo[]
but use filter(build => !!build)
rather than (build => build)
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.
Nice! I wasn't aware of that, fixed.
Signed-off-by: Tim deBoer <[email protected]>
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.
thx
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.
Functionality fixes the VM page now, thank you!
Implementation is great
What does this PR do?
Moving to svelte 5, state objects are proxied. Normally that's an implementation detail, but when you try to pass the proxies through rpc they can't be cloned and result in errors.
We could use $state.snapshot(build) every time we pass objects from the UI to the API, but we really shouldn't be passing whole objects to the backend and blindly trusting that the objects (including all properties) match what the backend knows anyway.
This changes the three affected API functions to accept ids instead of objects, and the backend looks up the objects before acting. Although it's slightly more work on the backend, this is a better/more robust API, and also avoids the svelte 5 proxy issue.
Screenshot / video of UI
N/A
What issues does this PR fix or reference?
Fixes #1304.
How to test this PR?
PR checks, delete a build, start a VM. Tests added to check we're passing strings.