Skip to content

Conversation

@manzoorwanijk
Copy link
Member

@manzoorwanijk manzoorwanijk commented May 9, 2022

Due to type conflict between v17 and v18 of @types/react, we have some TypeScript errors in certain components. For example on master branch, if you run cd projects/js-packages/components/ && pnpm tsc, you will see TS error(s).

Changes proposed in this Pull Request:

  • Override @types/react^17 peer dependency for @testing-library/react-hooks in order to use @types/react^18
  • Upgrade @types/react to v18

Jetpack product discussion

See #24256 (comment) and #24276 (comment)

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  • Checkout the PR
  • Run jetpack install --all or pnpm install
  • Confirm that you don't seen any MISSING PEER DEPENDENCY error.
  • Run cd projects/js-packages/components/ && pnpm tsc
  • Confirm that you don't see any TS error

Next Steps

I think it's the time to make TS check a part of the build process by simply running the TypeScript compiler CLI - tsc before running the actual build commands to avoid any errors being left in TS components.
It will be as simple as adding a "build": "tsc && ..." script to js-packages/components and plugins/jetpack etc.
Thoughts @Automattic/jetpack-agora ?

@manzoorwanijk manzoorwanijk added [Status] Needs Review This PR is ready for review. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [JS Package] Components labels May 9, 2022
@manzoorwanijk manzoorwanijk requested review from a team and anomiex May 9, 2022 11:21
@manzoorwanijk manzoorwanijk self-assigned this May 9, 2022
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello manzoorwanijk! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D80354-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@github-actions github-actions bot added the RNA label May 9, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2022

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ⚠️ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: June 7, 2022.
  • Scheduled code freeze: May 31, 2022.

@anomiex
Copy link
Contributor

anomiex commented May 9, 2022

  • Override @types/react^17 peer dependency for @testing-library/react-hooks in order to use @types/react^18
  • Upgrade @types/react to v18

I note we're still using react v17, not v18. Should the types package's version match the react version?

I think it's the time to make TS check a part of the build process by simply running the TypeScript compiler CLI - tsc before running the actual build commands to avoid any errors being left in TS components.
It will be as simple as adding a "build": "tsc && ..." script to js-packages/components and plugins/jetpack etc.

What impact would that have on build time? Could the actual build process report errors instead of having to run a separate build before the build?

@manzoorwanijk
Copy link
Member Author

manzoorwanijk commented May 9, 2022

I note we're still using react v17, not v18. Should the types package's version match the react version?

That may not make a huge difference in terms of types. The reason for my suggestion to use v18 is that there are already some underlying packages that already have v18 as a dependency. if you search for '@types/react' in the lockfile, you will see the number of packages that are already using v18.

What impact would that have on build time?

Yes, just a little bit.

Could the actual build process report errors instead of having to run a separate build before the build?

Yes, for that we need to wire up a TS checker plugin with webpack which won't be any different than tsc and instead is a little slower than tsc.

@anomiex
Copy link
Contributor

anomiex commented May 9, 2022

I note we're still using react v17, not v18. Should the types package's version match the react version?

That may not make a huge difference in terms of types. The reason for my suggestion to use v18 is that there are already some underlying packages that already have v18 as a dependency. if you search for '@types/react' in the lockfile, you will see the number of packages that are already using v18.

I see only four. All are other @types/* packages.

What impact would that have on build time?

Yes, just a little bit.

When you get around to trying it, let's be sure to quantify the impact. We might also try running tsc concurrently with the build instead of serially before it.

Some quick searches suggest that the tsconfig should have options like noEmit or emitDeclarationOnly so tsc doesn't write files.

Yes, for that we need to wire up a TS checker plugin with webpack which won't be any different than tsc and instead is a little slower than tsc.

Yeah, now that I look I see babel just understands the syntax well enough to ignore it, it doesn't actually process the types.

@manzoorwanijk
Copy link
Member Author

I see only four. All are other @types/* packages.

It's possible that more external packages will upgrade soon.

When you get around to trying it, let's be sure to quantify the impact. We might also try running tsc concurrently with the build instead of serially before it.

Oh yeah, running it in concurrently is a great idea. Thank you.

@manzoorwanijk
Copy link
Member Author

Some quick searches suggest that the tsconfig should have options like noEmit or emitDeclarationOnly so tsc doesn't write files.

Our tsconfig.base.json in js-tools already has noEmit set to true.

We can add emitDeclarationOnly for js-components to improve type experience.

@anomiex
Copy link
Contributor

anomiex commented May 9, 2022

It's possible that more external packages will upgrade soon.

And when they do, will they also want react 18 so we'll have to wait on those updates anyway? That's why #24276 brought @testing-library/react to only 12.1.5 instead of 13.x, for example.

@manzoorwanijk
Copy link
Member Author

manzoorwanijk commented May 9, 2022

And when they do, will they also want react 18 so we'll have to wait on those updates anyway?

Yeah we can do that. So, what's the easiest way to keep @types/react at v17 regardless of which package upgrades to v18?

@anomiex
Copy link
Contributor

anomiex commented May 11, 2022

So, what's the easiest way to keep @types/react at v17 regardless of which package upgrades to v18?

For direct dependencies from our stuff, just don't do the upgrade.

If we also need to worry about indirect deps of things, I suppose if we really needed to we could see about using the afterAllResolved hook in pnpmfile to throw an error if v18 is getting added. After first cleaning up the existing four deps pulling it in.

@manzoorwanijk
Copy link
Member Author

If we also need to worry about indirect deps of things, I suppose if we really needed to we could see about using the afterAllResolved hook in pnpmfile to throw an error if v18 is getting added. After first cleaning up the existing four deps pulling it in.

Do we have an example of how to do that? I have no idea 😃

@anomiex
Copy link
Contributor

anomiex commented May 11, 2022

Do we have an example of how to do that? I have no idea smiley

Not that I know of, we've never done it before. The whole JS ecosystem is designed for entirely the opposite use case, that dependencies can have their own copies of any deps they need instead of having to be locked to a particular shared version.

@manzoorwanijk
Copy link
Member Author

@anomiex I have made the changes to use v17.

Copy link
Contributor

@renatoagds renatoagds left a comment

Choose a reason for hiding this comment

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

Working fine. LGTM

@manzoorwanijk manzoorwanijk merged commit e5e811e into master May 17, 2022
@manzoorwanijk manzoorwanijk deleted the fix/@types/react-version-conflict branch May 17, 2022 15:41
@github-actions github-actions bot added this to the jetpack/11.0 milestone May 17, 2022
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label May 17, 2022
@github-actions
Copy link
Contributor

Great news! One last step: head over to your WordPress.com diff, D80354-code, and deploy it.
Once you've done so, come back to this PR and add a comment with your changeset ID.

Thank you!

@manzoorwanijk
Copy link
Member Author

r245802-wpcom

// Override @types/react* dependencies in order to use their specific versions
for ( const dep of [ '@types/react', '@types/react-dom', '@types/react-test-renderer' ] ) {
if ( pkg.dependencies?.[ dep ] ) {
pkg.dependencies[ dep ] = '17.x';
Copy link
Contributor

Choose a reason for hiding this comment

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

Just arbitrarily forcing every dep on these packages to "17.x" seems risky to me. But I guess we'll see what happens.

I was suggesting we avoid upgrading things that would bring in a 18.x dep rather than blindly overriding them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[JS Package] Components [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ RNA Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants