Skip to content

Commit 1e91ce8

Browse files
authored
Merge pull request #630 from Countly/rc-delay-merge-fix
RC ID change fix
2 parents b65211a + ed83dcd commit 1e91ce8

8 files changed

Lines changed: 304 additions & 238 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 26.1.2
2+
3+
- Delayed remote config refresh after merged device ID changes to reduce request ordering races.
4+
15
## 26.1.1
26

37
- Improved device metric detection capabilities.

cypress/e2e/bridged_utils.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function initMain(name, version) {
1515
}
1616

1717
const SDK_NAME = "javascript_native_web";
18-
const SDK_VERSION = "26.1.1";
18+
const SDK_VERSION = "26.1.2";
1919

2020
// tests
2121
describe("Bridged SDK Utilities Tests", () => {

cypress/e2e/device_id_change.cy.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,48 @@ describe("Set ID change tests ", () => {
275275
});
276276

277277
});
278+
279+
describe("Device ID remote config sequencing", () => {
280+
it("delays remote config refetch by 1 second after merge device ID changes", () => {
281+
hp.haltAndClearStorage(() => {
282+
var fakeServer = hp.createFakeRequestHandler({
283+
onRequest: function (req) {
284+
if (req.functionName === "fetch_remote_config_explicit") {
285+
return { status: 200, responseText: "{}" };
286+
}
287+
288+
return { status: 200, responseText: '{"result":"Success"}' };
289+
}
290+
});
291+
292+
var inst = Countly.init({
293+
app_key: hp.appKey,
294+
url: "https://test.count.ly",
295+
device_id: "old ID",
296+
debug: true,
297+
use_explicit_rc_api: true,
298+
disable_sdk_behavior_settings_updates: true,
299+
fake_request_handler: fakeServer.handler
300+
});
301+
302+
cy.wait(hp.sWait).then(() => {
303+
inst.remote_config = function () { };
304+
fakeServer.clear();
305+
Countly.change_id("new ID", true);
306+
});
307+
308+
cy.wait(300).then(() => {
309+
var earlyRemoteConfigRequest = fakeServer.getRequests().find((req) => req.functionName === "fetch_remote_config_explicit");
310+
expect(earlyRemoteConfigRequest).to.not.exist;
311+
});
312+
313+
cy.wait(1100).then(() => {
314+
var requests = fakeServer.getRequests();
315+
var remoteConfigRequest = requests.find((req) => req.functionName === "fetch_remote_config_explicit");
316+
317+
expect(remoteConfigRequest).to.exist;
318+
expect(remoteConfigRequest.params.device_id).to.equal("new ID");
319+
});
320+
});
321+
});
322+
});

cypress/e2e/sdk_info.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var Countly = require("../../lib/countly");
44
var hp = require("../support/helper.js");
55
const SDK_NAME = "javascript_native_web";
6-
const SDK_VERSION = "26.1.1";
6+
const SDK_VERSION = "26.1.2";
77

88
function initMain(name, version) {
99
Countly.init({

lib/countly.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
backoffCount: "cly_hc_backoff_count",
351351
consecutiveBackoffCount: "cly_hc_consecutive_backoff_count"
352352
});
353-
var SDK_VERSION = "26.1.1";
353+
var SDK_VERSION = "26.1.2";
354354
var SDK_NAME = "javascript_native_web";
355355

356356
// Using this on document.referrer would return an array with 17 elements in it. The 12th element (array[11]) would be the path we are looking for. Others would be things like password and such (use https://regex101.com/ to check more)
@@ -1200,6 +1200,7 @@
12001200
var _clientHintsPromise = /*#__PURE__*/new WeakMap();
12011201
var _pendingRequestBuffer = /*#__PURE__*/new WeakMap();
12021202
var _clientHintsBufferTimeoutId = /*#__PURE__*/new WeakMap();
1203+
var _changeIdRemoteConfigTimeoutId = /*#__PURE__*/new WeakMap();
12031204
var _initializeClientHints = /*#__PURE__*/new WeakMap();
12041205
var _flushPendingRequestBuffer = /*#__PURE__*/new WeakMap();
12051206
var _getAndSetServerConfig = /*#__PURE__*/new WeakMap();
@@ -1396,6 +1397,7 @@
13961397
_classPrivateFieldInitSpec(this, _clientHintsPromise, void 0);
13971398
_classPrivateFieldInitSpec(this, _pendingRequestBuffer, void 0);
13981399
_classPrivateFieldInitSpec(this, _clientHintsBufferTimeoutId, void 0);
1400+
_classPrivateFieldInitSpec(this, _changeIdRemoteConfigTimeoutId, void 0);
13991401
/**
14001402
* Fetch User-Agent Client Hints and cache values for metrics enrichment.
14011403
* @private
@@ -2201,6 +2203,10 @@
22012203
clearTimeout(_classPrivateFieldGet2(_clientHintsBufferTimeoutId, _this));
22022204
_classPrivateFieldSet2(_clientHintsBufferTimeoutId, _this, null);
22032205
}
2206+
if (_classPrivateFieldGet2(_changeIdRemoteConfigTimeoutId, _this)) {
2207+
clearTimeout(_classPrivateFieldGet2(_changeIdRemoteConfigTimeoutId, _this));
2208+
_classPrivateFieldSet2(_changeIdRemoteConfigTimeoutId, _this, null);
2209+
}
22042210
_classPrivateFieldSet2(_pendingRequestBuffer, _this, null);
22052211
_classPrivateFieldSet2(_clientHintsPromise, _this, null);
22062212
_classPrivateFieldSet2(_uaClientHints, _this, null);
@@ -2635,7 +2641,17 @@
26352641
if (_this.remote_config) {
26362642
_classPrivateFieldSet2(_remoteConfigs, _this, {});
26372643
_classPrivateFieldGet2(_setValueInStorage, _this).call(_this, "cly_remote_configs", _classPrivateFieldGet2(_remoteConfigs, _this));
2638-
_this.fetch_remote_config(_this.remote_config);
2644+
if (merge) {
2645+
if (_classPrivateFieldGet2(_changeIdRemoteConfigTimeoutId, _this)) {
2646+
clearTimeout(_classPrivateFieldGet2(_changeIdRemoteConfigTimeoutId, _this));
2647+
}
2648+
_classPrivateFieldSet2(_changeIdRemoteConfigTimeoutId, _this, setTimeout(function () {
2649+
_classPrivateFieldSet2(_changeIdRemoteConfigTimeoutId, _this, null);
2650+
_this.fetch_remote_config(_this.remote_config);
2651+
}, 1000));
2652+
} else {
2653+
_this.fetch_remote_config(_this.remote_config);
2654+
}
26392655
}
26402656
});
26412657
/**
@@ -7642,6 +7658,7 @@
76427658
_classPrivateFieldSet2(_clientHintsPromise, this, null);
76437659
_classPrivateFieldSet2(_pendingRequestBuffer, this, null);
76447660
_classPrivateFieldSet2(_clientHintsBufferTimeoutId, this, null);
7661+
_classPrivateFieldSet2(_changeIdRemoteConfigTimeoutId, this, null);
76457662
this.app_key = getConfig("app_key", _ob, null);
76467663
this.url = stripTrailingSlash(getConfig("url", _ob, ""));
76477664
this.serialize = getConfig("serialize", _ob, Countly.serialize);

0 commit comments

Comments
 (0)