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

Create a new object for console to have a prototype with toString method #11834

Merged
merged 2 commits into from
May 6, 2024

Conversation

psamim
Copy link
Contributor

@psamim psamim commented May 6, 2024

This is a fix for #11639

Objects possibly can have null prototypes. This causes them not to have toString() method leading to an error when doing substitution with console.warn() leading to the error "Cannot convert object to primitive value".

The error happens because both existing and incoming objects do not have .toString method. In the Chrome debugger, I saved incoming object as temp1 on the window and these are my observations:

console.log('%o', temp1)
> Uncaught TypeError: Cannot convert object to primitive value
console.log('%o', {...temp1} )
> {__typename: 'Configuration', totalNumber: 10, updatedAt: '2024-05-06T11:10:11.684236649Z' }
temp1.toString()
> Uncaught TypeError: temp1.toString is not a function

@apollo-cla
Copy link

@psamim: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

Copy link

netlify bot commented May 6, 2024

👷 Deploy request for apollo-client-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit eb30685

Copy link

changeset-bot bot commented May 6, 2024

🦋 Changeset detected

Latest commit: eb30685

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@psamim psamim changed the title Create a new object to have a prototype Create a new object for console to have a prototype with toString method May 6, 2024
@jerelmiller
Copy link
Member

Hey @psamim 👋

Thanks so much for digging into this! For the life of us, we can't seem to reproduce this in any way (the null prototype seems to work just fine for us in Chrome, Firefox and Node.js). I'm glad you've found a way to reproduce and a way to fix it! Out of curiosity, which environment are you running this in?

Would you mind adding a changeset to this PR? I'd be happy to accept this and get this out with the next patch version. Thanks again for the contribution!

Objects possibly can have null prototypes. This causes them not to have
toString() method leading to an error when doing substitution with
console.warn().
@psamim
Copy link
Contributor Author

psamim commented May 6, 2024

@jerelmiller

I am also running it in Chrome.

Sure, I added a change set.

@jerelmiller
Copy link
Member

So weird! This is what I see when I run it in Chrome.

Screenshot 2024-05-06 at 11 42 22 AM

🤷‍♂️.

Anyways, thanks for adding that changeset! Once I get the checks to run, I'll get this merged.

Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

🎉 Hoping this fixes this issue once and for all!

@jerelmiller jerelmiller merged commit 7d8aad4 into apollographql:main May 6, 2024
36 of 37 checks passed
@github-actions github-actions bot mentioned this pull request May 6, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants