Stop sharing a Data Library entry as on once its failed Remove switched it off

When Remove switched a layer off and then its destroy failed, the
manager published no visibility change, so the selection still listed
the entry as on: the link shared it as on and a reload restored it on
while its row read off. A failed Remove now drops the entry from what is
on and remembered whenever its layer ended up off.
This commit is contained in:
Sameh Khamis committed 2026-11-12 17:49:38 -08:00
1 parent 837eff7328
commit 8cca78bcd5
2 files changed
+47 -1

No files matched your search

+12 -1
View File
@@ -388,8 +388,19 @@ export function createDataLibrary({
if ( if (
isRegistered(id) && isRegistered(id) &&
!(await dataManager.unregisterLibraryLayer(libraryLayerId(id))) !(await dataManager.unregisterLibraryLayer(libraryLayerId(id)))
) ) {
// Switched off before teardown failed: it is no longer on, so the
// link and what is remembered must not say it is.
if (!dataManager.isEnabled?.(libraryLayerId(id))) {
selection = {
...selection,
on: selection.on.filter((other) => other !== id),
};
savedOn = savedOn.filter((other) => other !== id);
persist();
}
return false; return false;
}
selection = { selection = {
added: selection.added.filter((other) => other !== id), added: selection.added.filter((other) => other !== id),
on: selection.on.filter((other) => other !== id), on: selection.on.filter((other) => other !== id),
+35
View File
@@ -581,6 +581,41 @@ test('the URL keeps the opening lib= before availability loads and for entries i
library.destroy(); library.destroy();
}); });
test('a layer switched off before its teardown failed is no longer shared as on', async (t) => {
const manager = sealedManager(t);
const storage = memoryStorage();
const shareLink = shareLinkDouble();
const library = createDataLibrary({
entries,
ledger,
dataManager: manager,
services: {},
storage,
shareLink,
initialHash: '',
source: source({}),
});
await library.start();
await library.add('night-lights');
assert.equal(shareLink.encode(), '00');
const { module } = manager.layers.get('lib-night-lights');
const destroy = module.destroy;
module.destroy = async () => {
throw new Error('stuck');
};
t.mock.method(console, 'warn', () => {});
try {
assert.equal(await library.remove('night-lights'), false);
assert.equal(manager.isEnabled('lib-night-lights'), false);
assert.equal(shareLink.encode(), null);
const saved = JSON.parse(storage.store.get(LIBRARY_STORAGE_KEY));
assert.deepEqual(saved, { added: ['night-lights'], on: [] });
} finally {
module.destroy = destroy;
}
library.destroy();
});
test('zoom flies to an added layer through the caller, reset removes everything', async (t) => { test('zoom flies to an added layer through the caller, reset removes everything', async (t) => {
const manager = sealedManager(t); const manager = sealedManager(t);
const storage = memoryStorage(); const storage = memoryStorage();