Skip to content

Commit 8c00364

Browse files
Reset Workers runtime override on every init() call
Previously, calling init() with forceCloudflareWorkers:true would leave the module-level override set indefinitely. Subsequent init() calls without the option would silently inherit the forced value because nothing cleared it. Now sync unconditionally — set to true when explicitly forced, otherwise reset to null so navigator inference takes over. Fixes state bleed across init() calls in test suites and any multi-init scenario. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 937c0bc commit 8c00364

10 files changed

Lines changed: 32 additions & 30 deletions

dist/crowdhandler.cjs.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/crowdhandler.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/crowdhandler.esm.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/crowdhandler.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/crowdhandler.umd.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/crowdhandler.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/crowdhandler.umd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/crowdhandler.umd.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/init.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ function init(config) {
2727
}
2828
// Apply the Workers runtime override before constructing the Client, because
2929
// BaseClient's constructor reads isCloudflareWorkers() to decide whether to
30-
// touch axios.defaults. Only honoured when explicitly true — omission leaves
31-
// the navigator-based inference in place.
32-
if (((_a = config.options) === null || _a === void 0 ? void 0 : _a.forceCloudflareWorkers) === true) {
33-
(0, runtime_1.setCloudflareWorkersOverride)(true);
34-
}
30+
// touch axios.defaults. Unconditionally sync the module-level override so
31+
// repeated init() calls don't bleed state from prior invocations — omission
32+
// resets to null (navigator inference) rather than retaining a previously
33+
// forced value.
34+
(0, runtime_1.setCloudflareWorkersOverride)(((_a = config.options) === null || _a === void 0 ? void 0 : _a.forceCloudflareWorkers) === true ? true : null);
3535
// When a Workers context is provided, surface which signal drove the runtime
3636
// decision so debug logs can distinguish forced overrides from navigator
3737
// inference. Only emitted in debug mode.

src/init.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,13 @@ export function init(config: InitConfig): InitResult {
190190

191191
// Apply the Workers runtime override before constructing the Client, because
192192
// BaseClient's constructor reads isCloudflareWorkers() to decide whether to
193-
// touch axios.defaults. Only honoured when explicitly true — omission leaves
194-
// the navigator-based inference in place.
195-
if (config.options?.forceCloudflareWorkers === true) {
196-
setCloudflareWorkersOverride(true);
197-
}
193+
// touch axios.defaults. Unconditionally sync the module-level override so
194+
// repeated init() calls don't bleed state from prior invocations — omission
195+
// resets to null (navigator inference) rather than retaining a previously
196+
// forced value.
197+
setCloudflareWorkersOverride(
198+
config.options?.forceCloudflareWorkers === true ? true : null
199+
);
198200

199201
// When a Workers context is provided, surface which signal drove the runtime
200202
// decision so debug logs can distinguish forced overrides from navigator

0 commit comments

Comments
 (0)