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 error handling when name is a Symbol #28354

Closed

Conversation

jon-ressio
Copy link

Summary

Error discovered in a next.js application. Normal warning about complex types being passed to client components from a server component, but in this case the code that tries to render a warning/error message actually causes a different error/exception that masks the original error.
I initially filed the issue against next.js ( vercel/next.js#61966 ) with a repro example ( https://github.com/jon-ressio/vercel-prop-warn-error ).

I now think this is just from 1 case of String() not being called on name, so trying to concatenate a string and a symbol. I fixed the two places I saw the same pattern.

How did you test this change?

I have not tested it yet. I can figure out how to yarn link and build next against my build of react that includes the fix, but it would take me a bit. This feels like a pretty safe change, but if you'd like me to validate I can definitely do that, just let me know.

@sebmarkbage
Copy link
Collaborator

Thanks for reporting. I don't think this exactly the right fix. Because a client reference can never be extracted from a symbol export since it can't be referenced. Basically the proxy can't support symbols and should probably error in that case.

In particular the symbol trying to be extracted here is the Symbol.toStringTag symbol which maybe we should special case as being allowed in the proxy.

We can also special case detecting that this is a ClientReference when printing the error.

@sebmarkbage
Copy link
Collaborator

Alternative fix in #28355.

@jon-ressio
Copy link
Author

Excellent, really appreciate the crazy-fast turnaround to get it fixed the right way. See your tests, look good and should cover my case.

Thanks!

@sebmarkbage
Copy link
Collaborator

You got lucky I was working on improving error messages anyway. 😅

sebmarkbage added a commit that referenced this pull request Feb 19, 2024
…erence (#28355)

Alternative to #28354.

If a client reference is one of the props being describes as part of
another error, we call toString on it, which errors.

We should error explicitly when a Symbol prop is extracted.

However, pragmatically I added the toString symbol tag even though we
don't know what the real tostring will be but we also lie about the
typeof.

We can however in addition to this give it a different description
because describing this property as an object isn't quite right.

We probably could extract the export name but that's kind of renderer
specific and I just added this shared module to Fizz which doesn't have
that which is unfortunate an consequence.

For default exports we don't have a good name of what the alias was in
the receiver. Could maybe call it "default" but for now I just call it
"client".
@jon-ressio jon-ressio deleted the fix/symbol-name-handling branch April 12, 2024 20:55
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
…erence (facebook#28355)

Alternative to facebook#28354.

If a client reference is one of the props being describes as part of
another error, we call toString on it, which errors.

We should error explicitly when a Symbol prop is extracted.

However, pragmatically I added the toString symbol tag even though we
don't know what the real tostring will be but we also lie about the
typeof.

We can however in addition to this give it a different description
because describing this property as an object isn't quite right.

We probably could extract the export name but that's kind of renderer
specific and I just added this shared module to Fizz which doesn't have
that which is unfortunate an consequence.

For default exports we don't have a good name of what the alias was in
the receiver. Could maybe call it "default" but for now I just call it
"client".
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
…erence (#28355)

Alternative to #28354.

If a client reference is one of the props being describes as part of
another error, we call toString on it, which errors.

We should error explicitly when a Symbol prop is extracted.

However, pragmatically I added the toString symbol tag even though we
don't know what the real tostring will be but we also lie about the
typeof.

We can however in addition to this give it a different description
because describing this property as an object isn't quite right.

We probably could extract the export name but that's kind of renderer
specific and I just added this shared module to Fizz which doesn't have
that which is unfortunate an consequence.

For default exports we don't have a good name of what the alias was in
the receiver. Could maybe call it "default" but for now I just call it
"client".

DiffTrain build for commit c323f82.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants