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

fix: close https://github.com/cloudflare/workerd/issues/3620 #3621

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rxliuli
Copy link

@rxliuli rxliuli commented Feb 27, 2025

ref #3620

@rxliuli rxliuli requested review from a team as code owners February 27, 2025 03:28
Copy link


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@rxliuli
Copy link
Author

rxliuli commented Feb 27, 2025


I have read the CLA Document and I hereby sign the CLA


anonrig
anonrig previously approved these changes Feb 27, 2025
@@ -86,6 +86,7 @@ declare namespace Rpc {
: T extends Set<infer V> ? Set<Stubify<V>>
: T extends Array<infer V> ? Array<Stubify<V>>
: T extends ReadonlyArray<infer V> ? ReadonlyArray<Stubify<V>>
: T extends Rpc.Serializable<T> ? T
Copy link
Member

Choose a reason for hiding this comment

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

Won't this match plain objects, and thus bypass the next line below? So we won't end up recursively applying Stubify to the contents of objects?

I guess the problem you're experiencing (in your bug report) is that Date is matched by the line below, which then tries to recursively Stubify the properties of Date, and for some reason it is applying to all the prototype properties like toString, toDateString, toTimeString, and so on. I'm sort of surprised by this though, if [K in keyof T] actually matches prototype properties, why isn't it constantly getting hung up on Object.prototype properties which all objects have? Why only Date.prototype properties?

If this is just the way it works... then I guess what we actually need to do here is define a variant type that's narrower than Serializable which includes just the builtin types that are explicitly handled, like Date.

Copy link
Author

@rxliuli rxliuli Feb 27, 2025

Choose a reason for hiding this comment

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

Currently, in the definition of Serializable, except for the Stub/Stubable type which I am not sure what it is doing, the others seem like they should not use Stubify wrapping.

https://github.com/cloudflare/workerd/blob/5fe608c86ffa23efa21c9cd06136e5e79e653b55/types/defines/rpc.d.ts#L38C1-L71C16

For example, the RegExp type is also incorrect

image

Copy link
Member

Choose a reason for hiding this comment

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

I may be misreading as I don't know typescript super-well, but doesn't this part of Serializable match any plain object that is serializable?

    | {
        [K in keyof T]: K extends number | string ? Serializable<T[K]> : never;
      }

And won't that mean that your newly-added line will map any such plain object type to itself, thus bypassing the next line which would otherwise have recursively stubified the contents?

Copy link
Member

@kentonv kentonv left a comment

Choose a reason for hiding this comment

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

Per comment, I think this breaks things as-is.

@anonrig anonrig dismissed their stale review February 27, 2025 18:56

Removing per @kentonv's comments

@kentonv
Copy link
Member

kentonv commented Feb 27, 2025

@penalosa any thoughts on this?

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.

3 participants