react-component / util

Common Utils For React Component
util.vercel.app
MIT License
622 stars 176 forks source link

Fix supportRef function for preact #477

Closed SpaNb4 closed 5 months ago

SpaNb4 commented 9 months ago

Fixes the issue described in https://github.com/ant-design/ant-design/pull/44135

Why the issue exists: The highlighted code in rc-dropdown returns true for react and false for preact https://github.com/react-component/dropdown/blob/master/src/Overlay.tsx#L25

Screenshot ![image](https://github.com/react-component/util/assets/69504277/e353950b-c911-48b8-a6dc-2497cc60a3b0)

That's why the focus doesn't shift to the menu when using preact.

Now let's take a look at the supportRef code and add some console.log to it for debugging:

Screenshot ![image](https://github.com/react-component/util/assets/69504277/bfc83dfc-3919-4fe5-810f-966c003eafb8)

And here are the results:

react ![image](https://github.com/react-component/util/assets/69504277/f60fe8c2-e937-46de-94cd-60c598f7a73f)
preact ![image](https://github.com/react-component/util/assets/69504277/218a2621-e37a-476e-b863-b6cdf6576a2d)

So, based on the screenshots above, we can conclude that in the case of preact, the nodeOrComponent is a function, not an object, so the second condition is fulfilled and false is returned.

And to fix this I added an additional condition because in the screenshot above you can see that preact as well as react have a $$typeof property equal to Symbol(react.forward_ref) image

vercel[bot] commented 9 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
util ❌ Failed (Inspect) Dec 27, 2023 11:58am
SpaNb4 commented 9 months ago

@MadCcc @zombieJ Could you please review this PR?

mellis481 commented 7 months ago

@MadCcc @afc163 @zombieJ Can you please review and merge this PR? It's critical for my team.

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (5a3231f) 91.51% compared to head (105a436) 91.54%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #477 +/- ## ========================================== + Coverage 91.51% 91.54% +0.03% ========================================== Files 38 38 Lines 919 923 +4 Branches 280 284 +4 ========================================== + Hits 841 845 +4 Misses 76 76 Partials 2 2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

afc163 commented 7 months ago

@MadCcc 看看这个

SpaNb4 commented 6 months ago

@MadCcc Could you please review this PR?

mellis481 commented 6 months ago

@MadCcc Bump.

mellis481 commented 6 months ago

@MadCcc Help!

mellis481 commented 5 months ago

@afc163 Can you please help get this PR merged?

afc163 commented 5 months ago

ping @MadCcc @zombieJ

MadCcc commented 5 months ago

Could we add test for preact?

zombieJ commented 5 months ago

Checked for React 16, seems safe to merge.