Skip to content

Commit

Permalink
feat(client): remove staleTime (#2613)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

`staleTime` (previously `clientMaxAge`) has been removed. Check out `refetchInterval` instead. It should cover most of the cases. If not, we can look into adding this back later on.
  • Loading branch information
ubbe-xyz authored Aug 27, 2021
1 parent 1c1e841 commit 08349c3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/client/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export async function signOut(options = {}) {

/** @param {import("types/react-client").SessionProviderProps} props */
export function SessionProvider(props) {
const { children, basePath, staleTime = 0 } = props
const { children, basePath } = props

if (basePath) __NEXTAUTH.basePath = basePath

Expand Down Expand Up @@ -230,14 +230,14 @@ export function SessionProvider(props) {
// If there is no time defined for when a session should be considered
// stale, then it's okay to use the value we have until an event is
// triggered which updates it
(staleTime === 0 && !event) ||
!event ||
// If the client doesn't have a session then we don't need to call
// the server to check if it does (if they have signed in via another
// tab or window that will come through as a "stroage" event
// event anyway)
(staleTime > 0 && __NEXTAUTH._session === null) ||
__NEXTAUTH._session === null ||
// Bail out early if the client session is not stale yet
(staleTime > 0 && _now() < __NEXTAUTH._lastSync + staleTime)
_now() < __NEXTAUTH._lastSync
) {
return
}
Expand All @@ -254,7 +254,7 @@ export function SessionProvider(props) {
}

__NEXTAUTH._getSession()
}, [staleTime])
}, [])

React.useEffect(() => {
// Listen for storage events and update session if event fired from
Expand Down Expand Up @@ -320,7 +320,7 @@ export function SessionProvider(props) {
* If passed 'appContext' via getInitialProps() in _app.js
* then get the req object from ctx and use that for the
* req value to allow _fetchData to
* work seemlessly in getInitialProps() on server side
* work seamlessly in getInitialProps() on server side
* pages *and* in _app.js.
*/
async function _fetchData(path, { ctx, req = ctx?.req } = {}) {
Expand Down
5 changes: 0 additions & 5 deletions types/react-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ export interface SessionProviderProps {
session?: Session
baseUrl?: string
basePath?: string
/**
* The amount of time (in seconds) after a session should be considered stale.
* If set to `0` (default), the session will never be re-fetched.
*/
staleTime?: number
/**
* A time interval (in seconds) after which the session will be re-fetched.
* If set to `0` (default), the session is not polled.
Expand Down
2 changes: 0 additions & 2 deletions types/tests/react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ client.SessionProvider({
session: clientSession,
baseUrl: "https://foo.com",
basePath: "/",
staleTime: 1234,
})

// $ExpectType ReactElement<any, any> | null
Expand All @@ -94,6 +93,5 @@ client.SessionProvider({
},
baseUrl: "https://foo.com",
basePath: "/",
staleTime: 1234,
refetchInterval: 4321,
})

0 comments on commit 08349c3

Please sign in to comment.