Next-auth: Why does NextAuth re-render children whenever browser regains focus?

Created on 20 Jul 2020  路  3Comments  路  Source: nextauthjs/next-auth

Your question
Why is NextAuth re-rendering all my components when my browser is regaining focus. See the gif below:

Kapture 2020-07-20 at 23 03 00

What are you trying to do
NextAuth shouldn't re-render all the children components every time the browser regains focus. Below is a screenshot where the NextAuth wrapper is selected in Chrome devtools:

Screenshot 2020-07-20 at 11 04 32 PM

Documentation feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.

  • [x] Found the documentation helpful
  • [ ] Found documentation but was incomplete
  • [x] Could not find relevant documentation
  • [ ] Found the example project helpful
  • [ ] Did not find the example project helpful
question

All 3 comments

Session state in v3 is updated if a window regains focus (along with some other events). If content is wrapped in a provider this will trigger a re-render depending on how you have structured your page and created your components.

A change in session state is also propagated (using events) to other windows for the site to ensure all tabs/windows are in sync and that a user does not appear to be 'signed in' when they are actually signed out (e.g. after a session has expired).

This is very much by design. SWR from Vercel has a similar functionality.

If you would like this behaviour to be optional when using the <Provider>, please do raise a feature request explaining the scenario and the rationale so we can understand how to approach creating an option for this and communicating it clearly in a way that would work for you and other users.

On the surface of it, I don't see why we couldn't provide an option to disable this feature if there was demand for it, though I'm not inclined to change the default behaviour in this case.

@iaincollins Thank you for your reply. I wanted to understand more about why this design was done. Thank you for clarifying that.

@ghoshnirmalya Thanks for asking!

It's always very useful to have questions that are very clear like this as it helps highlighting what we need to do a better job of and to question assumptions about default behaviour (both what is obvious and not obvious, as well as what is good or not good default behaviour!).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

simonbbyrne picture simonbbyrne  路  3Comments

ghoshnirmalya picture ghoshnirmalya  路  3Comments

benoror picture benoror  路  3Comments

bscaspar picture bscaspar  路  3Comments

ryanbahan picture ryanbahan  路  3Comments