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

Allow File (and other object types) to be send over RPC #255

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

robin-drexler
Copy link
Member

This is a request for comment PR, @lemonmade

The main intention was to allow File to be send over the RPC layer.

Before we'd try to decode individual properties of the object, essentially destroying it.

Now we're only doing this for basic objects, similar to how it's done in encode.

This basically allows any supported value to be send as is now.

I'm not sure if that introduces unintended side-effects tho, hence the request for comments because I know we had issues with infinite loops prior.

Alternatively, and if we want to play it safe, we'd also just add another exception for File, like we already had one for ArrayBuffer.

🎩

I tested this down to Safari 13. In earlier versions, even the vite prod build would produce JS that safari doesn't understand and I didn't wanna set up the legacy build.

  • check out rd/file-support-tophat (which is another branch that has some more changes to tophat this
  • run yarn example:kitchen-sink-vite
  • Go to http://localhost:5173/
  • Click on React worker
  • Open console
  • Select a file. Preferably an image or something a browser can display
  • A blob url should be logged in the console. That is being logged from the worker
  • Copy and paste it into your address bar
  • The file should render
image image

This comment has been minimized.

}),
{},
) as any;
if (isBasicObject(value)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

If it's not basic, it'll be returned as is further down

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if there's "non basic" cases, where we'd need to iterate over properties.

Copy link
Member

@lemonmade lemonmade left a comment

Choose a reason for hiding this comment

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

Thanks Robin, LGTM! This is the intended behavior, so I think the current behavior is a bug. Can you add a changeset for a patch change?

@robin-drexler robin-drexler merged commit 9037436 into main Feb 12, 2024
5 checks passed
@robin-drexler robin-drexler deleted the rd/file-support branch February 12, 2024 21: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.

2 participants