Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@augustjk
Copy link
Member

While working making the top level examples directory to part of the npm workspaces here #4111, I noticed the code that wraps the custom element with createComponent() was failing type check as the React type imported in the nextjs example project was a different copy than the one used by @lit-labs/react, and due to things like unique symbol type and function overloading, copies are not compatible. In that PR, I solved the issue by de-duping the @types/react package in the monorepo but we may eventually have valid reasons to have multiple copies of @types/react in the monorepo (should we add projects/tests with React 17, for instance).

The type change done here allows for the nextjs example project and @lit-labs/react to have different React types, and also only specifies APIs we use from React so users could create their own bag of React functions rather than passing in the whole module.

@changeset-bot
Copy link

changeset-bot bot commented Aug 26, 2023

🦋 Changeset detected

Latest commit: c24e08d

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

This PR includes changesets to release 1 package
Name Type
@lit-labs/react 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

@github-actions
Copy link
Contributor

github-actions bot commented Aug 26, 2023

📊 Tachometer Benchmark Results

Summary

nop-update

  • this-change, tip-of-tree, previous-release: unsure 🔍 -10% - +4% (-2.12ms - +0.78ms)
    this-change vs tip-of-tree

render

  • this-change: 72.99ms - 76.92ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -5% - +4% (-1.48ms - +1.17ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +3% (-1.00ms - +1.46ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +4% (-0.99ms - +1.86ms)
    this-change vs tip-of-tree

update

  • this-change: 771.77ms - 791.66ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -4% - +6% (-3.35ms - +5.23ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -1% - +2% (-1.41ms - +3.05ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +2% (-12.50ms - +14.40ms)
    this-change vs tip-of-tree

update-reflect

  • this-change: 756.95ms - 770.44ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -1% - +2% (-9.37ms - +13.78ms)
    this-change vs tip-of-tree

Results

this-change

render

VersionAvg timevs
72.99ms - 76.92ms-

update

VersionAvg timevs
771.77ms - 791.66ms-

update-reflect

VersionAvg timevs
756.95ms - 770.44ms-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
29.16ms - 30.92ms-unsure 🔍
-5% - +4%
-1.48ms - +1.17ms
unsure 🔍
-9% - +4%
-2.71ms - +1.21ms
tip-of-tree
tip-of-tree
29.19ms - 31.19msunsure 🔍
-4% - +5%
-1.17ms - +1.48ms
-unsure 🔍
-8% - +5%
-2.61ms - +1.42ms
previous-release
previous-release
29.04ms - 32.54msunsure 🔍
-4% - +9%
-1.21ms - +2.71ms
unsure 🔍
-5% - +9%
-1.42ms - +2.61ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
82.60ms - 89.23ms-unsure 🔍
-4% - +6%
-3.35ms - +5.23ms
unsure 🔍
-3% - +8%
-2.28ms - +6.68ms
tip-of-tree
tip-of-tree
82.24ms - 87.70msunsure 🔍
-6% - +4%
-5.23ms - +3.35ms
-unsure 🔍
-3% - +6%
-2.80ms - +5.32ms
previous-release
previous-release
80.70ms - 86.72msunsure 🔍
-8% - +3%
-6.68ms - +2.28ms
unsure 🔍
-6% - +3%
-5.32ms - +2.80ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
18.87ms - 21.04ms-unsure 🔍
-10% - +4%
-2.12ms - +0.78ms
unsure 🔍
-13% - -0%
-2.91ms - +0.00ms
tip-of-tree
tip-of-tree
19.67ms - 21.59msunsure 🔍
-4% - +11%
-0.78ms - +2.12ms
-unsure 🔍
-10% - +3%
-2.15ms - +0.59ms
previous-release
previous-release
20.43ms - 22.38msunsure 🔍
-0% - +15%
-0.00ms - +2.91ms
unsure 🔍
-3% - +11%
-0.59ms - +2.15ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
55.49ms - 57.34ms-unsure 🔍
-2% - +3%
-1.00ms - +1.46ms
unsure 🔍
-2% - +3%
-0.86ms - +1.66ms
tip-of-tree
tip-of-tree
55.37ms - 57.00msunsure 🔍
-3% - +2%
-1.46ms - +1.00ms
-unsure 🔍
-2% - +2%
-1.01ms - +1.35ms
previous-release
previous-release
55.16ms - 56.87msunsure 🔍
-3% - +2%
-1.66ms - +0.86ms
unsure 🔍
-2% - +2%
-1.35ms - +1.01ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
132.93ms - 136.10ms-unsure 🔍
-1% - +2%
-1.41ms - +3.05ms
unsure 🔍
-1% - +2%
-1.56ms - +2.92ms
tip-of-tree
tip-of-tree
132.13ms - 135.26msunsure 🔍
-2% - +1%
-3.05ms - +1.41ms
-unsure 🔍
-2% - +2%
-2.37ms - +2.09ms
previous-release
previous-release
132.25ms - 135.42msunsure 🔍
-2% - +1%
-2.92ms - +1.56ms
unsure 🔍
-2% - +2%
-2.09ms - +2.37ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
46.40ms - 48.86ms-unsure 🔍
-2% - +4%
-0.99ms - +1.86ms
unsure 🔍
-3% - +3%
-1.42ms - +1.33ms
tip-of-tree
tip-of-tree
46.49ms - 47.90msunsure 🔍
-4% - +2%
-1.86ms - +0.99ms
-unsure 🔍
-3% - +1%
-1.41ms - +0.45ms
previous-release
previous-release
47.06ms - 48.28msunsure 🔍
-3% - +3%
-1.33ms - +1.42ms
unsure 🔍
-1% - +3%
-0.45ms - +1.41ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
789.23ms - 807.87ms-unsure 🔍
-2% - +2%
-12.50ms - +14.40ms
unsure 🔍
-2% - +1%
-13.37ms - +11.53ms
tip-of-tree
tip-of-tree
787.91ms - 807.29msunsure 🔍
-2% - +2%
-14.40ms - +12.50ms
-unsure 🔍
-2% - +1%
-14.59ms - +10.86ms
previous-release
previous-release
791.22ms - 807.72msunsure 🔍
-1% - +2%
-11.53ms - +13.37ms
unsure 🔍
-1% - +2%
-10.86ms - +14.59ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
797.13ms - 814.02ms-unsure 🔍
-1% - +2%
-9.37ms - +13.78ms
unsure 🔍
-2% - +1%
-17.11ms - +6.52ms
tip-of-tree
tip-of-tree
795.47ms - 811.28msunsure 🔍
-2% - +1%
-13.78ms - +9.37ms
-unsure 🔍
-2% - +0%
-18.94ms - +3.94ms
previous-release
previous-release
802.61ms - 819.14msunsure 🔍
-1% - +2%
-6.52ms - +17.11ms
unsure 🔍
-0% - +2%
-3.94ms - +18.94ms
-

tachometer-reporter-action v2 for Benchmarks

// Interface that includes parts of the React module that we use. This allows
// users to construct an object with just the needed methods and prevents type
// incompatibilities when there are multiple React types being used.
interface ReactLike {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we export this? I could see someone using this with satisfies to make an object to pass to several createComponent calls. If so, make the comment a doc comment.

@augustjk augustjk force-pushed the labs-react-loose-option-type branch from 75d668a to c24e08d Compare August 28, 2023 22:45
Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz left a comment

Choose a reason for hiding this comment

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

Nice!

* createElement,
* } satisfies ReactLike;
*
* createComponnt({
Copy link
Contributor

Choose a reason for hiding this comment

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

createComponnt -> createComponent

'@lit-labs/react': patch
---

Make option type for the React module we accept to be looser. This lets users provide a smaller object with just the needed API and mitigate type incompatibilities when multiple copies of React types are present.
Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz Aug 28, 2023

Choose a reason for hiding this comment

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

for first sentence, I think I prefer the PR title way of specifying what type is loosened.
"Loosen createComponent's options.react type so it only includes the parts of the React API that are used.", or alternatively to be looser -> looser.

@augustjk
Copy link
Member Author

Upon further exploration and thought, I'm less convinced that this is a valuable change to the package.

My main motivation for this was to allow multiple copies of React to type check for the case of our examples directory having a different version of React from the rest of the monorepo but that's actually a valid error as React breaks when multiple copies are used.

The only value, then, would be that users can provide a subset of the React module, but that also shoehorns us into only using those API and anything additional would be a breaking change.

@augustjk augustjk closed this Aug 29, 2023
@augustjk augustjk deleted the labs-react-loose-option-type branch October 6, 2023 23:43
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