Skip to content

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

Merged
merged 3 commits into from
Feb 11, 2025

Conversation

deboer-tim
Copy link
Contributor

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.

@deboer-tim deboer-tim requested a review from a team as a code owner February 10, 2025 22:21
@deboer-tim deboer-tim requested review from benoitf, dgolovin, SoniaSandler and cdrage and removed request for a team February 10, 2025 22:21
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]>
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}`));
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Comment on lines 110 to 112
const builds = buildIds
.map(id => this.history.getHistory().find(build => build.id === id))
.filter(build => build) as BootcBuildInfo[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Contributor

@benoitf benoitf left a comment

Choose a reason for hiding this comment

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

thx

Copy link
Contributor

@cdrage cdrage left a 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

@cdrage cdrage merged commit 1199526 into podman-desktop:main Feb 11, 2025
6 checks passed
@deboer-tim deboer-tim deleted the rpc-ids branch February 11, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Virtual Machine tab no longer refreshing
3 participants