TylerBarnes / gatsby-plugin-transition-link

A link component for page transitions in gatsby
537 stars 70 forks source link

Many renders when logging to console from render #176

Open mysterybear opened 4 years ago

mysterybear commented 4 years ago

Hi,

Howcome this plugin causes this behaviour?

gif of problem

Code for this is a minimal diff on gatsby-starter-default just adding this plugin and swapping out Gatsby's Links with this plugin's, and then adding console.log's to the components' render blocks. Here: https://github.com/mysterybear/issue-demo-transition-link-renders

TylerBarnes commented 4 years ago

Hey @mysterybear ! The reason for this was actually a poor API design decision I made originally. Essentially this is because the transition state/status is passed to each page as props. Since those props keep changing it keeps re-rendering the page. Since removing this would be a breaking change I added an option to disable it. See https://github.com/TylerBarnes/gatsby-plugin-transition-link/pull/149 for the change. You should be able to use it like so:

{
      resolve: 'gatsby-plugin-transition-link',
      options: {
        injectPageProps: false,
      },
    },

You wont be able to get transition info from page component props anymore with that setting disabled. I'm not sure if this affects any of the AniLink components (haven't checked yet). In V2 injectPageProps: false will become the default to avoid the negative performance impact this can cause.