Skip to content

Conversation

@maxbrieiev
Copy link
Contributor

In React, the Ref type corresponds to the Ref type in preact core. However, preact/compat re-exports the Ref type from preact/hooks instead of from core.

The following snippet does not produce a type error in React, but it does when using preact:

export const baz = (
  ref: React.ForwardedRef<HTMLElement>
): React.Ref<HTMLElement> => ref;

In preact it producesType 'ForwardedRef<HTMLElement>' is not assignable to type 'Ref<HTMLElement>'.

This pull requests fixes this issue.

The commit improves React compatibility by re-exporting `Ref` from core instead of hooks.
@coveralls
Copy link

Coverage Status

coverage: 99.611%. remained the same
when pulling 92fd386 on maxbrieiev:main
into d19017e on preactjs:main.

Copy link
Member

@rschristian rschristian left a comment

Choose a reason for hiding this comment

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

Cheers, thanks for going beyond too! It'll hopefully correct similar mismatches in the future.

@rschristian rschristian merged commit 4c20c23 into preactjs:main Jun 2, 2024
@JoviDeCroock JoviDeCroock mentioned this pull request Jun 30, 2024
miguelrk added a commit to netzo/dsa that referenced this pull request Jul 9, 2024
…to DOM issues

See the following for the changes introduced which might have caused this:
- preactjs/preact#4409
- preactjs/preact#4421
- preactjs/preact#4403
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.

Type errors involving forwardRef and Ref in the compatibility layer.

3 participants