Skip to content

Commit 6c485bb

Browse files
Fixes
1 parent 4e580be commit 6c485bb

4 files changed

Lines changed: 20 additions & 16 deletions

File tree

src/__tests__/browserSuites/push-fallback.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ export function testFallback(fetchMock, assert) {
287287
// Periodic fetch due to polling (memberships is not fetched due to smart pausing)
288288
fetchMock.getOnce(url(settings, '/splitChanges?s=1.2&since=1457552649999'), function () {
289289
const lapse = Date.now() - start;
290-
assert.true(nearlyEqual(lapse, MILLIS_STREAMING_DISABLED_CONTROL + settings.scheduler.featuresRefreshRate, 100), 'fetch due to fourth fallback to polling');
290+
assert.true(nearlyEqual(lapse, MILLIS_STREAMING_DISABLED_CONTROL + settings.scheduler.featuresRefreshRate), 'fetch due to fourth fallback to polling');
291291
return { status: 200, body: splitChangesMock3 };
292292
});
293293
fetchMock.getOnce(url(settings, '/splitChanges?s=1.2&since=1457552669999'), function () {
294294
const lapse = Date.now() - start;
295-
assert.true(nearlyEqual(lapse, MILLIS_STREAMING_DISABLED_CONTROL + settings.scheduler.featuresRefreshRate * 2, 100), 'fetch due to fourth fallback to polling');
295+
assert.true(nearlyEqual(lapse, MILLIS_STREAMING_DISABLED_CONTROL + settings.scheduler.featuresRefreshRate * 2), 'fetch due to fourth fallback to polling');
296296
return { status: 200, body: { splits: [], since: 1457552669999, till: 1457552669999 } };
297297
});
298298

src/__tests__/offline/browser.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ tape('Browser offline mode', function (assert) {
112112
});
113113

114114
const sdkReadyFromCache = (client) => () => {
115+
assert.equal(factory.settings.storage.type, 'MEMORY', 'In localhost mode, storage must fallback to memory storage');
116+
115117
const clientStatus = client.__getStatus();
116118
assert.equal(clientStatus.isReadyFromCache, true, 'If ready from cache, READY_FROM_CACHE status must be true');
117119
assert.equal(clientStatus.isReady, false, 'READY status must not be set before READY_FROM_CACHE');

src/settings/storage/browser.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
import { isLocalStorageAvailable } from '@splitsoftware/splitio-commons/src/utils/env/isLocalStorageAvailable';
2-
import { STORAGE_MEMORY } from '@splitsoftware/splitio-commons/src/utils/constants';
2+
import { LOCALHOST_MODE, STORAGE_MEMORY } from '@splitsoftware/splitio-commons/src/utils/constants';
33

44
const STORAGE_LOCALSTORAGE = 'LOCALSTORAGE';
55

66
export function validateStorage(settings) {
77
let {
88
log,
9+
mode,
910
storage: {
1011
type,
1112
options = {},
1213
prefix
1314
} = { type: STORAGE_MEMORY },
1415
} = settings;
16+
let __originalType;
17+
18+
const fallbackToMemory = () => {
19+
__originalType = type;
20+
type = STORAGE_MEMORY;
21+
};
22+
23+
// In localhost mode, fallback to Memory storage and track original type to emit SDK_READY_FROM_CACHE if corresponds.
24+
// ATM, other mode settings (e.g., 'consumer') are ignored in client-side API, and so treated as standalone.
25+
if (mode === LOCALHOST_MODE && type === STORAGE_LOCALSTORAGE) {
26+
fallbackToMemory();
27+
}
1528

1629
// If an invalid storage type is provided OR we want to use LOCALSTORAGE and
1730
// it's not available, fallback into MEMORY
1831
if (type !== STORAGE_MEMORY && type !== STORAGE_LOCALSTORAGE ||
1932
type === STORAGE_LOCALSTORAGE && !isLocalStorageAvailable()) {
20-
type = STORAGE_MEMORY;
33+
fallbackToMemory();
2134
log.error('Invalid or unavailable storage. Fallback into MEMORY storage');
2235
}
2336

2437
return {
2538
type,
2639
options,
2740
prefix,
41+
__originalType
2842
};
2943
}

types/splitio.d.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,18 +1261,6 @@ declare namespace SplitIO {
12611261
* @returns {IManager} The manager instance.
12621262
*/
12631263
manager(): IManager,
1264-
/**
1265-
* Returns a manager instance of the SDK to explore available information.
1266-
* @function manager
1267-
* @returns {IManager} The manager instance.
1268-
*/
1269-
manager(): IManager,
1270-
/**
1271-
* Returns a manager instance of the SDK to explore available information.
1272-
* @function manager
1273-
* @returns {IManager} The manager instance.
1274-
*/
1275-
manager(): IManager,
12761264
/**
12771265
* User consent API.
12781266
* @property UserConsent

0 commit comments

Comments
 (0)