Skip to content
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 @reach/router Link base type #3546

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

edoroshenko
Copy link

  • Type of contribution: fix

Other notes: This change fixes the problem when flow@1.106.x expects all props of HTMLAnchorElement to be present in a Link instance.

@@ -71,7 +71,7 @@ declare module '@reach/router' {
|}>;

declare export type LinkProps<State> = {
...$Shape<HTMLAnchorElement>,
...React$ElementProps<string>,
Copy link
Contributor

@Hypnosphi Hypnosphi Sep 2, 2019

Choose a reason for hiding this comment

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

Why not ...React$ElementProps<'a'>?

Copy link
Contributor

Choose a reason for hiding this comment

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

@reach/router spreads Link props over <a/> element: https://github.com/reach/router/blob/master/src/index.js#L385-L398

Copy link
Author

Choose a reason for hiding this comment

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

My thought was to make it more generic. I could imagine that Link component would render another element like span.

Copy link
Contributor

Choose a reason for hiding this comment

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

@reach/router is very accessibility-centric, so I don't think they will ever allow using spans as links

Copy link
Contributor

Choose a reason for hiding this comment

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

They actually even advertise using native links as a feature =)
https://reach.tech/router/accessibility

@bluie1983

This comment has been minimized.

@pascalduez
Copy link
Member

Doesn't feel like the right fix.

React$ElementProps<string> nor React$ElementProps<'a'> does not bring all the same validation.

Current issue reproduction.

...$Shape<HTMLAnchorElement> is quite weird to be honest.

@edoroshenko
Copy link
Author

@pascalduez what would be the right one?

@Hypnosphi
Copy link
Contributor

Hypnosphi commented Sep 3, 2019

React$ElementProps<string> nor React$ElementProps<'a'> does not bring all the same validation.

Oh I see. Looks like Flow doesn't validate DOM props at all:

https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVBLAtgBzgJwBdkwBDAZzACUBTUgY2KnzizAHJ87H31hgwAEgCiADxw1Gw-C3wAuMAAsuUMOUVwArjAAmYAEY01hfBgB2Ac1QAeUkpUBeAN4BGAEwBmAL5hgAPlQgA

It should probably be fixed with facebook/flow#7569

@pascalduez
Copy link
Member

what would be the right one?

I guess React$ElementProps<'a'> is indeed what we want, the issue with merging now is we loose the DOM props validation. But this is broken anyway from Flow 0.106.x so...

@pascalduez
Copy link
Member

What's missing to be able to move here, I guess adding tests to assert the proper intended behaviour?

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

Successfully merging this pull request may close these issues.

None yet

5 participants