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: enable ref forwarding with forwardRef #9892

Merged
merged 3 commits into from
Jan 10, 2019

Conversation

DSchau
Copy link
Contributor

@DSchau DSchau commented Nov 12, 2018

Note: I think we should minimally make this more than a patch release per
React docs

This will make the Link component work more like many would expect
(innerRef is confusing!), but it does come at the cost of requiring
React 16.3. I think it's a reasonable trade off, however.

cc @LekoArts I validated this with a sample repo, but want to pull this down and make sure it fixes your issue, as well?

Note: I think we should minimally make this more than a patch release per
[React
docs](https://reactjs.org/docs/forwarding-refs.html#note-for-component-library-maintainers)

This will make the Link component work more like many would expect
(innerRef is confusing!), but it does come at the cost of requiring
React 16.3. I think it's a reasonable trade off, however.
@DSchau DSchau requested a review from a team as a code owner November 12, 2018 22:08
@DSchau DSchau requested a review from a team November 12, 2018 22:08
@@ -97,7 +97,6 @@ class GatsbyLink extends React.Component {
/* eslint-disable no-unused-vars */
activeClassName: $activeClassName,
activeStyle: $activeStyle,
ref: $ref,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@LekoArts this fixes the bug re: accessing ref.

@pieh
Copy link
Contributor

pieh commented Nov 13, 2018

React 16.3. I think it's a reasonable trade off, however.

gatsby requires react@^16.4.2 so this is fine

Note: I think we should minimally make this more than a patch release per

This is tricky - if this is breaking change then we would need bump major version both in gatsby-link and gatsby (you import Link from gatsby and not gatsby-link).

@DSchau
Copy link
Contributor Author

DSchau commented Dec 7, 2018

@pieh I'll check this out locally, but I think this is a valuable change we should get in.

I don't think it is actually a breaking change if we already require >= 16.3 in Gatsby.

@DSchau
Copy link
Contributor Author

DSchau commented Dec 7, 2018

Few things:

  • This does break React@<16.3.0 support, but since we have a peerDep of 16.4.1, that's probably OK
  • Here's a reproduction showing both ref and innerRef working; so this isn't a breaking change if anyone was using innerRef, either
    • Note: this will break both page-2 and page-3 links (on purpose) because I'm just preventing the default on click with an event listener from the ref

@KyleAMathews
Copy link
Contributor

Gatsby v2 was released after react 16.4.2 was out so that's the minimum version we support.

We could probably get away with bumping the minimum required react version in the future with sufficient reason.

@DSchau
Copy link
Contributor Author

DSchau commented Dec 8, 2018

@KyleAMathews yeah - I'm thinking once some of the newer, useful stuff launches, e.g. Suspense with SSR, Hooks, etc. that could be a good time to bump the peerDep.

In effect--if it makes the code we maintain smaller, cleaner, etc. that's a good time to make that change.

What do you think?

arcticicestudio added a commit to nordtheme/web that referenced this pull request Dec 13, 2018
The currently used version of "Gatsby Link" (1) uses the `innerRef` prop
to allow `ref` access to the underlying DOM element (necessary for
animations). In order to wrap animated components the `ref` is
necessary and is therefore now forwarded.

The legacy behavior of "Gatsby Link" is about to change in the future to
the `React.forwardRef` API.
See gatsbyjs/gatsby#9892 for more details.

References:
  (1) https://www.gatsbyjs.org/docs/gatsby-link

Associated epic: GH-69
GH-64
@KyleAMathews
Copy link
Contributor

Yeah, the next thing that should really impact us is suspense as we could replace a lot of our preloading/prefetching/page transition code with it.

Hooks are great but I don't think there's anywhere we'd use them in the Gatsby runtime?

@wardpeet
Copy link
Contributor

@DSchau are we good to merge this?

PR looks allright to me

Any updates you want to give @LekoArts about issue testing?

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

LGTM

@LekoArts
Copy link
Contributor

I think when I tested it back then everything worked 🤔

@DSchau DSchau merged commit b6d9775 into gatsbyjs:master Jan 10, 2019
@DSchau DSchau deleted the gatsby-link/forward-ref branch January 10, 2019 14:01
@DSchau
Copy link
Contributor Author

DSchau commented Jan 10, 2019

@LekoArts LekoArts mentioned this pull request Jan 10, 2019
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
Note: I think we should minimally make this more than a patch release per
[React docs](https://reactjs.org/docs/forwarding-refs.html#note-for-component-library-maintainers)

This will make the Link component work more like many would expect
(innerRef is confusing!), but it does come at the cost of requiring
React 16.3. I think it's a reasonable trade off, however.

cc @LekoArts I validated this with a sample repo, but want to pull this down and make sure it fixes your issue, as well?

<!--
  Q. Which branch should I use for my pull request?
  A. Use `master` branch (probably).

  Q. Which branch if my change is a bug fix for Gatsby v1?
  A. In this case, you should use the `v1` branch

  Q. Which branch if I'm still not sure?
  A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :)

  Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2.

  Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/
-->
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.

6 participants