Skip to content

Commit ae1b72d

Browse files
authored
chore(zero): Statically disable mutation recovery (#3519)
This allows dead code elimination to remove the mutation recovery code.
1 parent fe4e0b1 commit ae1b72d

File tree

4 files changed

+36
-23
lines changed

4 files changed

+36
-23
lines changed

packages/replicache/src/replicache-impl.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ import {
124124

125125
declare const TESTING: boolean;
126126

127+
declare const process: {
128+
env: {
129+
['DISABLE_MUTATION_RECOVERY']?: string | undefined;
130+
};
131+
};
132+
127133
/**
128134
* The maximum number of time to call out to getAuth before giving up
129135
* and throwing an error.
@@ -202,7 +208,7 @@ export class ReplicacheImpl<MD extends MutatorDefs = {}> {
202208
readonly name: string;
203209

204210
readonly #subscriptions: SubscriptionsManager;
205-
readonly #mutationRecovery: MutationRecovery;
211+
readonly #mutationRecovery: MutationRecovery | undefined;
206212

207213
/**
208214
* Client groups gets disabled when the server does not know about it.
@@ -475,16 +481,18 @@ export class ReplicacheImpl<MD extends MutatorDefs = {}> {
475481
const clientGroupIDResolver = resolver<string>();
476482
this.#clientGroupIDPromise = clientGroupIDResolver.promise;
477483

478-
this.#mutationRecovery = new MutationRecovery({
479-
delegate: this,
480-
lc: this.#lc,
481-
enableMutationRecovery,
482-
wrapInOnlineCheck: this.#wrapInOnlineCheck.bind(this),
483-
wrapInReauthRetries: this.#wrapInReauthRetries.bind(this),
484-
isPullDisabled: this.#isPullDisabled.bind(this),
485-
isPushDisabled: this.#isPushDisabled.bind(this),
486-
clientGroupIDPromise: this.#clientGroupIDPromise,
487-
});
484+
if (!process.env.DISABLE_MUTATION_RECOVERY) {
485+
this.#mutationRecovery = new MutationRecovery({
486+
delegate: this,
487+
lc: this.#lc,
488+
enableMutationRecovery,
489+
wrapInOnlineCheck: this.#wrapInOnlineCheck.bind(this),
490+
wrapInReauthRetries: this.#wrapInReauthRetries.bind(this),
491+
isPullDisabled: this.#isPullDisabled.bind(this),
492+
isPushDisabled: this.#isPushDisabled.bind(this),
493+
clientGroupIDPromise: this.#clientGroupIDPromise,
494+
});
495+
}
488496

489497
this.#onPersist = initOnPersistChannel(
490498
this.name,
@@ -1498,18 +1506,20 @@ export class ReplicacheImpl<MD extends MutatorDefs = {}> {
14981506
return ex;
14991507
}
15001508

1501-
recoverMutations(): Promise<boolean> {
1502-
const result = this.#mutationRecovery.recoverMutations(
1503-
this.#ready,
1504-
this.perdag,
1505-
this.#idbDatabase,
1506-
this.#idbDatabases,
1507-
this.#kvStoreProvider.create,
1508-
);
1509-
if (TESTING) {
1510-
void this.onRecoverMutations(result);
1509+
recoverMutations(): Promise<boolean> | void {
1510+
if (!process.env.DISABLE_MUTATION_RECOVERY) {
1511+
const result = this.#mutationRecovery!.recoverMutations(
1512+
this.#ready,
1513+
this.perdag,
1514+
this.#idbDatabase,
1515+
this.#idbDatabases,
1516+
this.#kvStoreProvider.create,
1517+
);
1518+
if (TESTING) {
1519+
void this.onRecoverMutations(result);
1520+
}
1521+
return result;
15111522
}
1512-
return result;
15131523
}
15141524

15151525
/**

packages/replicache/src/test-util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class ReplicacheTest<
7474
}
7575

7676
recoverMutations(): Promise<boolean> {
77-
return this.#impl.recoverMutations();
77+
return this.#impl.recoverMutations() as Promise<boolean>;
7878
}
7979

8080
get perdag() {

packages/shared/src/build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export function makeDefine(mode = 'unknown') {
5959
getVersion('replicache'),
6060
),
6161
['process.env.ZERO_VERSION']: JSON.stringify(getVersion('zero')),
62+
['process.env.DISABLE_MUTATION_RECOVERY']: 'false',
6263
['TESTING']: 'false',
6364
};
6465
if (mode === 'unknown') {

packages/zero/tool/build.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ async function verifyDependencies(external) {
101101

102102
async function buildZeroClient() {
103103
const define = makeDefine('unknown');
104+
define['process.env.DISABLE_MUTATION_RECOVERY'] = 'true';
105+
104106
const entryPoints = forBundleSizeDashboard
105107
? {zero: basePath('src/zero.ts')}
106108
: {

0 commit comments

Comments
 (0)