Skip to content

Commit

Permalink
Merge pull request #255 from Shopify/rd/file-support
Browse files Browse the repository at this point in the history
Allow `File` (and other object types) to be send over RPC
  • Loading branch information
robin-drexler authored Feb 12, 2024
2 parents 42cbc05 + c89ffb7 commit 9037436
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-masks-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@remote-ui/rpc': patch
---

allow File and other object types to be send over the RPC layer
20 changes: 9 additions & 11 deletions packages/rpc/src/encoding/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ export function createBasicEncoder(api: EncodingStrategyApi): EncodingStrategy {
return value as any;
}

if (value instanceof ArrayBuffer) {
return value;
}

if (Array.isArray(value)) {
return value.map((value) => decode(value, retainedBy));
}
Expand Down Expand Up @@ -209,13 +205,15 @@ export function createBasicEncoder(api: EncodingStrategyApi): EncodingStrategy {
return proxy as any;
}

return Object.keys(value).reduce(
(object, key) => ({
...object,
[key]: decode((value as any)[key], retainedBy),
}),
{},
) as any;
if (isBasicObject(value)) {
return Object.keys(value).reduce(
(object, key) => ({
...object,
[key]: decode((value as any)[key], retainedBy),
}),
{},
) as any;
}
}

return value as any;
Expand Down

0 comments on commit 9037436

Please sign in to comment.