Comparing version 1.1.0 to 1.1.1
@@ -785,2 +785,9 @@ import { useEffect, useLayoutEffect, createContext, useContext, useState, createElement, useRef, useCallback, useDebugValue } from 'react'; | ||
} | ||
else { | ||
// data and newData are deeply equal | ||
// it should be safe to broadcast the stale data | ||
newState.data = stateRef.current.data; | ||
// At the end of this function, `brocastState` invokes the `onStateUpdate` function, | ||
// which takes care of avoiding the re-render | ||
} | ||
// For global state, it's possible that the key has changed. | ||
@@ -942,7 +949,12 @@ // https://github.com/vercel/swr/pull/1058 | ||
function next() { | ||
// Use the passed interval | ||
// ...or invoke the function with the updated data to get the interval | ||
var interval = isFunction(refreshInterval) | ||
? refreshInterval(data) | ||
: refreshInterval; | ||
// We only start next interval if `refreshInterval` is not 0, and: | ||
// - `force` is true, which is the start of polling | ||
// - or `timer` is not 0, which means the effect wasn't canceled | ||
if (refreshInterval && timer !== -1) { | ||
timer = setTimeout(execute, refreshInterval); | ||
if (interval && timer !== -1) { | ||
timer = setTimeout(execute, interval); | ||
} | ||
@@ -977,3 +989,3 @@ } | ||
// the suspense boundary. | ||
if (suspense && isUndefined(data)) { | ||
if (suspense && isUndefined(data) && key) { | ||
throw isUndefined(error) ? revalidate(WITH_DEDUPE) : error; | ||
@@ -980,0 +992,0 @@ } |
@@ -787,2 +787,9 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
} | ||
else { | ||
// data and newData are deeply equal | ||
// it should be safe to broadcast the stale data | ||
newState.data = stateRef.current.data; | ||
// At the end of this function, `brocastState` invokes the `onStateUpdate` function, | ||
// which takes care of avoiding the re-render | ||
} | ||
// For global state, it's possible that the key has changed. | ||
@@ -944,7 +951,12 @@ // https://github.com/vercel/swr/pull/1058 | ||
function next() { | ||
// Use the passed interval | ||
// ...or invoke the function with the updated data to get the interval | ||
var interval = isFunction(refreshInterval) | ||
? refreshInterval(data) | ||
: refreshInterval; | ||
// We only start next interval if `refreshInterval` is not 0, and: | ||
// - `force` is true, which is the start of polling | ||
// - or `timer` is not 0, which means the effect wasn't canceled | ||
if (refreshInterval && timer !== -1) { | ||
timer = setTimeout(execute, refreshInterval); | ||
if (interval && timer !== -1) { | ||
timer = setTimeout(execute, interval); | ||
} | ||
@@ -979,3 +991,3 @@ } | ||
// the suspense boundary. | ||
if (suspense && isUndefined(data)) { | ||
if (suspense && isUndefined(data) && key) { | ||
throw isUndefined(error) ? revalidate(WITH_DEDUPE) : error; | ||
@@ -982,0 +994,0 @@ } |
@@ -15,3 +15,3 @@ import * as revalidateEvents from './constants/revalidate-events'; | ||
dedupingInterval: number; | ||
refreshInterval?: number; | ||
refreshInterval?: number | ((latestData: Data | undefined) => number); | ||
refreshWhenHidden?: boolean; | ||
@@ -18,0 +18,0 @@ refreshWhenOffline?: boolean; |
{ | ||
"name": "swr", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "React Hooks library for remote data fetching", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
159975
3159