Skip to content

Commit 7628e67

Browse files
committed
implement fix
1 parent a434a37 commit 7628e67

File tree

11 files changed

+67
-44
lines changed

11 files changed

+67
-44
lines changed

packages/build-config/vite.config.mjs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const entryPoints = [
1010
'./src/debugging.ts',
1111
'./src/deprecations.ts',
1212
'./src/canary-features.ts',
13-
'./src/runtime.ts',
1413
];
1514

1615
export default createConfig(

packages/core-types/src/-private.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ type UniversalKey =
1616
| 'RequestCache'
1717
// @warp-drive/core-types/request
1818
| 'SkipCache'
19-
| 'EnableHydration';
19+
| 'EnableHydration'
20+
// @warp-drive/core-types/runtime
21+
| 'WarpDriveRuntimeConfig';
2022

2123
type TransientKey =
2224
// @ember-data/tracking

packages/build-config/src/runtime.ts packages/core-types/src/runtime.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { LOG_CONFIG } from './-private/utils/logging';
1+
import type { LOG_CONFIG } from '@warp-drive/build-config/-private/utils/logging';
22

3-
const RuntimeConfig = {
3+
import { getOrSetUniversal } from './-private';
4+
5+
const RuntimeConfig: { debug: Partial<LOG_CONFIG> } = getOrSetUniversal('WarpDriveRuntimeConfig', {
46
debug: {},
5-
};
7+
});
68

79
const settings = globalThis.sessionStorage?.getItem('WarpDriveRuntimeConfig');
810
if (settings) {

packages/core-types/vite.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const entryPoints = [
1818
'./src/utils.ts',
1919
// non-public
2020
'./src/-private.ts',
21+
'./src/runtime.ts',
2122
];
2223

2324
export default createConfig(

packages/graph/src/-private/-diff.ts

+17-31
Original file line numberDiff line numberDiff line change
@@ -234,42 +234,24 @@ function _compare<T>(
234234
// however: if the new remote order matches the current local order
235235
// we can disregard the change notification generation so long as
236236
// we are not configured to reset on remote update (which is deprecated)
237-
if (DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE) {
238-
if (i < priorLocalLength) {
239-
const priorLocalMember = priorLocalState![i];
240-
if (remoteClearsLocal) {
241-
if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {
242-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, no-console
243-
!changed && console.log(`changed because member !== prevMember && remoteClearsLocal`);
244-
}
245-
changed = true;
246-
} else if (priorLocalMember !== member) {
247-
if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {
248-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, no-console
249-
!changed && console.log(`changed because priorLocalMember !== member && member !== prevMember`);
250-
}
251-
changed = true;
252-
}
253-
}
254-
} else {
255-
if (i < priorLocalLength) {
256-
const priorLocalMember = priorLocalState![i];
257-
if (priorLocalMember !== member) {
258-
if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {
259-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, no-console
260-
!changed && console.log(`changed because priorLocalMember !== member && member !== prevMember`);
261-
}
262-
changed = true;
263-
}
264-
} else if (i < finalLength) {
265-
// if we have exceeded the length of priorLocalState and we are within the range
266-
// of the finalState then we must have changed
237+
238+
if (i < priorLocalLength) {
239+
const priorLocalMember = priorLocalState![i];
240+
if (priorLocalMember !== member) {
267241
if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {
268242
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, no-console
269-
!changed && console.log(`changed because priorMember !== member && index >= priorLocalLength`);
243+
!changed && console.log(`changed because priorLocalMember !== member && member !== prevMember`);
270244
}
271245
changed = true;
272246
}
247+
} else if (i < finalLength) {
248+
// if we have exceeded the length of priorLocalState and we are within the range
249+
// of the finalState then we must have changed
250+
if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {
251+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, no-console
252+
!changed && console.log(`changed because priorMember !== member && index >= priorLocalLength`);
253+
}
254+
changed = true;
273255
}
274256

275257
// if remote order hasn't changed but local order differs
@@ -280,6 +262,10 @@ function _compare<T>(
280262
if (equalLength && !changed && i < priorLocalLength) {
281263
const priorLocalMember = priorLocalState![i];
282264
if (priorLocalMember !== prevMember) {
265+
if (DEBUG_RELATIONSHIP_NOTIFICATIONS) {
266+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, no-console
267+
!changed && console.log(`changed because priorLocalMember !== prevMember && remoteClearsLocal`);
268+
}
283269
changed = true;
284270
}
285271
}

packages/request/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getRuntimeConfig, setLogging } from '@warp-drive/build-config/runtime';
1+
import { getRuntimeConfig, setLogging } from '@warp-drive/core-types/runtime';
22

33
export { RequestManager as default } from './-private/manager';
44
export { createDeferred } from './-private/future';

packages/store/src/-private/managers/notification-manager.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,20 @@ export default class NotificationManager {
250250
);
251251
}
252252
}
253-
} else if (LOG_METRIC_COUNTS) {
254-
count(`DISCARDED notify ${'type' in identifier ? identifier.type : '<document>'} ${value} ${key}`);
253+
} else {
254+
if (LOG_NOTIFICATIONS) {
255+
log(
256+
'notify',
257+
'discarded',
258+
`${'type' in identifier ? identifier.type : 'document'}`,
259+
identifier.lid,
260+
`${value}`,
261+
key || ''
262+
);
263+
}
264+
if (LOG_METRIC_COUNTS) {
265+
count(`DISCARDED notify ${'type' in identifier ? identifier.type : '<document>'} ${value} ${key}`);
266+
}
255267
}
256268

257269
return hasSubscribers;

packages/store/src/-private/store-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
} from '@warp-drive/build-config/deprecations';
2121
import { DEBUG, TESTING } from '@warp-drive/build-config/env';
2222
import { assert } from '@warp-drive/build-config/macros';
23-
import { getRuntimeConfig, setLogging } from '@warp-drive/build-config/runtime';
2423
import type { Cache } from '@warp-drive/core-types/cache';
2524
import type { Graph } from '@warp-drive/core-types/graph';
2625
import type {
@@ -30,6 +29,7 @@ import type {
3029
} from '@warp-drive/core-types/identifier';
3130
import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';
3231
import { EnableHydration, SkipCache } from '@warp-drive/core-types/request';
32+
import { getRuntimeConfig, setLogging } from '@warp-drive/core-types/runtime';
3333
import type { ResourceDocument } from '@warp-drive/core-types/spec/document';
3434
import type {
3535
CollectionResourceDocument,

packages/unpublished-test-infra/src/test-support/asserts/assert-notification.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type Store from '@ember-data/store';
88
import type { DocumentCacheOperation, NotificationType } from '@ember-data/store';
99
import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier';
1010

11-
type Counter = { count: number };
11+
type Counter = { count: number; delivered: number; ignored: number };
1212
type NotificationStorage = Map<
1313
StableDocumentIdentifier | StableRecordIdentifier | 'document' | 'resource',
1414
Map<NotificationType | DocumentCacheOperation, Counter | Map<string | symbol, Counter>>
@@ -34,7 +34,7 @@ function getCounter(
3434
let bucketStorage = identifierStorage.get(bucket);
3535
if (!bucketStorage) {
3636
if (bucket === 'added' || bucket === 'removed' || bucket === 'updated' || bucket === 'state') {
37-
bucketStorage = { count: 0 };
37+
bucketStorage = { count: 0, delivered: 0, ignored: 0 };
3838
} else {
3939
bucketStorage = new Map();
4040
}
@@ -46,7 +46,7 @@ function getCounter(
4646
const _key = key || Symbol.for(bucket);
4747
counter = bucketStorage.get(_key)!;
4848
if (!counter) {
49-
counter = { count: 0 };
49+
counter = { count: 0, delivered: 0, ignored: 0 };
5050
bucketStorage.set(_key, counter);
5151
}
5252
} else {
@@ -79,7 +79,15 @@ function setupNotifications(context: TestContext, store: Store) {
7979
counter.count++;
8080

8181
// @ts-expect-error TS is bad at curried overloads
82-
return originalNotify.apply(notifications, [identifier, bucket, key]);
82+
const scheduled = originalNotify.apply(notifications, [identifier, bucket, key]);
83+
84+
if (scheduled) {
85+
counter.delivered++;
86+
} else {
87+
counter.ignored++;
88+
}
89+
90+
return scheduled;
8391
};
8492
}
8593

tests/ember-data__graph/ember-cli-build.js

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ module.exports = async function (defaults) {
2020

2121
setConfig(app, __dirname, {
2222
compatWith: process.env.EMBER_DATA_FULL_COMPAT ? '99.0' : null,
23+
deprecations: {
24+
DEPRECATE_STORE_EXTENDS_EMBER_OBJECT: false,
25+
},
2326
});
2427

2528
app.import('node_modules/@warp-drive/diagnostic/dist/styles/dom-reporter.css');

tests/ember-data__graph/tests/integration/graph/diff-preservation-test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@ module('Integration | Graph | Diff Preservation', function (hooks) {
12031203
// watch for changes
12041204
assert.watchNotifications(store);
12051205

1206+
console.groupCollapsed('initial state');
12061207
const Identifier = (type: string, id: string) => {
12071208
return store.identifierCache.getOrCreateRecordIdentifier({ type, id });
12081209
};
@@ -1243,6 +1244,8 @@ module('Integration | Graph | Diff Preservation', function (hooks) {
12431244
[comment1Identifier, comment2Identifier, comment3Identifier, comment4Identifier],
12441245
'initial data is correct'
12451246
);
1247+
console.groupEnd();
1248+
console.groupCollapsed('remove comment 2');
12461249

12471250
// remove comment 2
12481251
store._join(() => {
@@ -1270,6 +1273,8 @@ module('Integration | Graph | Diff Preservation', function (hooks) {
12701273
[comment1Identifier, comment3Identifier, comment4Identifier],
12711274
'comment 2 is removed'
12721275
);
1276+
console.groupEnd();
1277+
console.groupCollapsed('push a new remote state that matches the local state');
12731278

12741279
// push a new remote state that matches the local state
12751280
store._join(() => {
@@ -1303,6 +1308,9 @@ module('Integration | Graph | Diff Preservation', function (hooks) {
13031308
'We should have no notifciations after remote push matches local state'
13041309
);
13051310

1311+
console.groupEnd();
1312+
console.groupCollapsed('push an update that does not match the local state');
1313+
13061314
// push an update that does not match the local state
13071315
store._join(() => {
13081316
graph.push({
@@ -1330,6 +1338,8 @@ module('Integration | Graph | Diff Preservation', function (hooks) {
13301338
// check state is updated
13311339
const data4 = graph.getData(userIdentifier, 'comments');
13321340
assert.arrayStrictEquals(data4.data, [comment1Identifier, comment4Identifier], 'state is updated');
1341+
1342+
console.groupEnd();
13331343
});
13341344

13351345
test('updateRelationship operation matching localState does not produce a notification for a committed addition', function (assert) {

0 commit comments

Comments
 (0)