-
Notifications
You must be signed in to change notification settings - Fork 1k
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: avoid naming conflict with client
prop
#7024
Conversation
Hey @esteban-url I tried this out and it definitely fixes the problem in the repo you provided in the issue 🎉 I wonder if we could solve even more potential name collisions by instead doing something like Any of the changes in this PR will be breaking? In theory a user could be using these additional variables within their cells in their projects and renaming these will break the user's cell in that case. Maybe we should find a good place in the docs to add this information too? Especially if it is a breaking change. Just my initial ideas feel free to disagree or ignore because I've got no expertise in this area. Will need the maintainers to give their feedback too of course. |
@Josh-Walker-GM thanks for validating it!
I guess this could be a breaking change, I don't know how to determine if it is. All the framework tests are passing, so there's that. Tagging @Tobbe and @jtoar as I think they are the ones that introduced and reviewed the impacted lines. Do you have any more insight or comments on this PR, and the changes Josh is proposing? |
Thanks for the PR @esteban-url, and thanks for jumping in @Josh-Walker-GM! This is definitely a breaking change. If someone was passing a prop called We knew spreading so many (and big) objects out as props could/would cause conflicts. It's the same with path- and query parameters. So far we've decided the DX win of not having to go dig for your data within objects (as you would if we wrapped everything) was worth the potential conflicts. Having a linting rule for I'll bring this one up with the rest of the team. |
Thanks @Tobbe! I understand the considerations the team had to make. I'll keep the PR updated until you've had time to discuss it. |
16 replays were recorded for c5a6f37. 16 PassedrequireAuth graphql checks
|
Will prioritize getting this one discussed with the rest of the core team this week @esteban-url |
thats awesome thanks @jtoar, please let me know if there is anything that could be added to this PR to help get it merged. testing/docs/codemods? Because this isn't really "public" i think having a code mod would be the most impactful, addition, you know, in case someone uses |
Hey @esteban-url, we discussed this one last week. The scope of the discussion quickly expanded from renaming just "client" to renaming all the props returned by the GraphQL client that aren't "data", "loading", or "error". But we didn't settle on a name for what that would be. We threw around "result" and "queryResult". We want to avoid putting "gql" specifically because we envision Cells being GraphQL-agnostic in a way at some point. So this one is still at a bit of a stand still, though I'm following up again this week on the discussion. Yeah this would need docs and a codemod; it's breaking so even if it was merged as soon as this week, it wouldn't be available till v5. But you could always use it right away by upgrading to canary. |
@esteban-url follow up, the team wants to go with "queryResult". I know this is a bit different from what you have here in this PR. What are you thoughts about it in general? And would you like to try to take it on? No pressure though! |
errorCode={error.graphQLErrors?.[0]?.extensions?.['code'] as string} | ||
errorCode={ | ||
// Use the ad-hoc QueryResultWithErrorCode type to access the errorCode | ||
(queryResult as QueryResultWithErrorCode).errorCode ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that adding an ad-hoc type is the best way to handle the errorCode
. would love feedback on this fix 🤓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change to existing behavior, right? Where exactly is errorCode
coming from? Why weren't we using it before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This showed up when running the test suite on this test: https://github.com/redwoodjs/redwood/blob/main/packages/web/src/components/createCell.test.tsx#L260
Before my change the queryRest
destructuring was overriding the errorCode
prop:
<Failure
error={error}
errorCode={error.graphQLErrors?.[0]?.extensions?.['code'] as string}
{...props}
updating={loading}
{...queryRest} // <---- Overwrites errorCode because it's one of `queryRest` members. it also overwrites error
/>
But because it's now a part of queryResult
the errorCode
is never set. So the test referenced above fails.
Should we be destructuring and overwriting error
and errorCode
?
errorCode={error.graphQLErrors?.[0]?.extensions?.['code'] as string} | ||
errorCode={ | ||
// Use the ad-hoc QueryResultWithErrorCode type to access the errorCode | ||
(queryResult as QueryResultWithErrorCode).errorCode ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change to existing behavior, right? Where exactly is errorCode
coming from? Why weren't we using it before?
@esteban-url just a heads up that you're free to keep merging main into this branch but it's really not that necessary till it's close to being merged, or you see a merge conflict you want to resolve. Just trying to save you some work or vigilance |
got it, thanks for the tip. Every now and then go thru my pr and update them so its no big deal, but I'll probably leave them now 😄 |
Hey @esteban-url hope you don't mind me pushing to the branch. We wanted to add a codemod for this change. This means whenever a user was using one of the parameters which now lives within |
hey @Josh-Walker-GM no problem at all! thanks for your help getting this through! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @esteban-url, and nice codemod and set of tests @Josh-Walker-GM!
* 'main' of github.com:redwoodjs/redwood: (50 commits) Use formatCacheKey() when deleting a key (redwoodjs#7362) fix(deps): update dependency @types/node to v16.18.14 (redwoodjs#7739) chore(deps): update dependency @npmcli/arborist to v6.2.4 (redwoodjs#7741) chore(deps): update dependency @replayio/playwright to v0.3.24 (redwoodjs#7738) chore(deps): update dependency @testing-library/react to v14 (redwoodjs#7737) chore(deps): update dependency @testing-library/dom to v9 (redwoodjs#7736) chore(deps): update dependency @types/vscode to v1.76.0 (redwoodjs#7729) chore(deps): update dependency zx to v7.2.0 (redwoodjs#7731) fix(deps): update dependency webpack-bundle-analyzer to v4.8.0 (redwoodjs#7735) fix(deps): update dependency babel-plugin-polyfill-corejs3 to v0.7.1 (redwoodjs#7732) fix(deps): update dependency msw to v1.1.0 (redwoodjs#7733) chore(deps): update dependency @clerk/clerk-react to v4.12.0 (redwoodjs#7728) fix(deps): update dependency @types/node to v16.18.13 (redwoodjs#7727) fix: change isDataEmpty, add codemod, fix codemod (redwoodjs#7704) fix: avoid naming conflict with `client` prop (redwoodjs#7024) fix(deps): update jest monorepo to v29.4.3 (redwoodjs#7651) chore(deps): update dependency @auth0/auth0-spa-js to v2 (redwoodjs#7524) fix(deps): update dependency @types/aws-lambda to v8.10.111 (redwoodjs#7726) fix(deps): update dependency @clerk/clerk-sdk-node to v4.7.7 (redwoodjs#7725) chore(deps): update dependency supertokens-node to v13.1.2 (redwoodjs#7714) ...
@esteban-url - looks like type safety is broken for this - should I create an issue for the issue?
|
@shivghai Please go ahead and create a new issue for the TS problem. |
Fixes #6946
Problem:
When you use a prop named client it will be overwritten by the graphQL client. Detailed explanation and example in the issue #6946
Solution
Renaming the prop will avoid the name conflict and allow a
client
prop in any cell