fix(viewer): a file the viewer refuses no longer stops it opening for every image (#646)
The viewer checked every loaded image before opening and threw on the first identity it refused, such as a folder name holding a backslash. It now leaves those files out of the arrow-through list, and clicking one shows its details panel instead of the viewer.
This commit is contained in:
@@ -311,3 +311,42 @@ test('on a video the image keys and Space do nothing, as the toolbar disables th
|
||||
await page.evaluate(() => new Promise(requestAnimationFrame));
|
||||
await expect(viewer(page)).not.toHaveClass(/\bviewer-fullscreen\b/);
|
||||
});
|
||||
|
||||
/** #646: the listing carries one file whose folder name holds a backslash, as a Windows-style prefix makes on Linux. */
|
||||
async function withBackslashFile(page) {
|
||||
await page.route(/\/prompt_manager\/images\/output\?/, async route => {
|
||||
const response = await route.fetch(), body = await response.json();
|
||||
if (body.images?.length > 1) {
|
||||
const copy = body.images[1];
|
||||
body.images.splice(1, 0, {...copy, path: `model.safetensors\\2026-11-17/${copy.filename}`, relative_path: `model.safetensors\\2026-11-17/${copy.filename}`});
|
||||
}
|
||||
await route.fulfill({response, json: body});
|
||||
});
|
||||
}
|
||||
|
||||
test('a file the viewer refuses is left out, and the others still open (#646)', async ({ page }) => {
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await withBackslashFile(page);
|
||||
await page.setViewportSize({ width: 1600, height: 1100 });
|
||||
await openProduction(page, 'images', 'dark');
|
||||
const cards = await page.locator(CARDS).count();
|
||||
await page.locator(CARDS).first().locator('.image-open').click();
|
||||
await expect(position(page)).toContainText(`1 of ${cards - 1}`);
|
||||
await page.keyboard.press('ArrowRight');
|
||||
await expect(position(page)).toContainText('2 of ');
|
||||
await expect(viewer(page).locator('#viewer-title')).not.toContainText('model.safetensors');
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
|
||||
test('the refused file itself opens its details instead of the viewer (#646)', async ({ page }) => {
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await withBackslashFile(page);
|
||||
await page.setViewportSize({ width: 1600, height: 1100 });
|
||||
await openProduction(page, 'images', 'dark');
|
||||
await page.locator(`${CARDS}[data-image-key*="model.safetensors"] .image-open`).click();
|
||||
await expect(page.getByRole('complementary', {name: 'Selected image details'}).getByRole('alert')).toHaveText('Could not read prompts from this file.');
|
||||
await expect(viewer(page)).toHaveCount(0);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -38,6 +38,19 @@ test('viewer rejects empty duplicate or unknown identity', () => {
|
||||
assert.equal(view.state.index, 0); view.dispose();
|
||||
});
|
||||
|
||||
test('viewer leaves out an identity it refuses instead of refusing to open (#646)', () => {
|
||||
const items = entries().slice(0, 3);
|
||||
items.splice(1, 0, {...items[1], path: 'model.safetensors\\2026-11-17/x.png', filename: 'x.png'});
|
||||
const view = session({items, initialKey: '0:folder/0.png'});
|
||||
assert.deepEqual(view.state, {key:'0:folder/0.png',index:0,total:3,phase:'stopped',requested:false,mediaReady:false});
|
||||
view.navigate(1); assert.equal(view.state.key, '1:folder/1.png');
|
||||
view.navigate(1); assert.equal(view.state.key, '0:folder/2.png');
|
||||
view.dispose();
|
||||
// The refused file itself is not in the viewer, and a collection of refused files has nothing to open.
|
||||
assert.throws(() => session({items, initialKey: '1:model.safetensors\\2026-11-17/x.png'}), TypeError);
|
||||
assert.throws(() => session({items: [items[1]], initialKey: '0:folder/0.png'}), TypeError);
|
||||
});
|
||||
|
||||
test('viewer ignores stale readiness after navigation and disposal', () => {
|
||||
let calls = 0;
|
||||
const view = session({items:entries(),initialKey:'0:folder/0.png',onChange:() => calls++,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { createImageStream, withItem, imageKey, countLine, captionDate, scopeLab
|
||||
import { createImageCard } from './image-card.mjs';
|
||||
import { layoutImages, visibleImages, gridMetrics, stacksCardInfo } from './image-layout.mjs';
|
||||
import { mountFileInspector } from './file-inspector.mjs';
|
||||
import { createInspectionController } from './inspection-state.mjs';
|
||||
import { createInspectionController, rootedFileAdapter } from './inspection-state.mjs';
|
||||
import { mountSelectionBar } from './images-selection.mjs';
|
||||
import { scrollToPageTop } from './sticky-chrome.mjs';
|
||||
import { createPromptSender } from './prompt-sender.mjs';
|
||||
@@ -374,6 +374,8 @@ export function mountImages(main, api, parentScope, {embedded = false, fetchPage
|
||||
}
|
||||
function previewImage(image) {
|
||||
if (!image) return;
|
||||
// #646: a file the viewer can't open (a backslash in a folder name) shows its details panel instead.
|
||||
try { rootedFileAdapter.validate(image); } catch { inspect(image); return; }
|
||||
mediaViewer.open({items:state.items,selectedKey:imageKey(image),trigger:document.activeElement});
|
||||
}
|
||||
/** The concept media card (image-card.mjs): the image opens the viewer, Info inspects (D7–D11, D19). */
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import {rootedFileAdapter} from './inspection-state.mjs';
|
||||
|
||||
/** A viewer visits only the descriptors loaded by its opening query. */
|
||||
/** One descriptor the adapter refuses is left out, so it never keeps the viewer from opening on the others (#646). */
|
||||
function openable(adapter, item) {
|
||||
try { adapter.validate(item); return true; } catch (error) { if (error instanceof TypeError) return false; throw error; }
|
||||
}
|
||||
|
||||
/** A viewer visits only the descriptors loaded by its opening query that its adapter accepts. */
|
||||
export function createViewerSession({items, initialKey, onChange = () => {}, setTimer = setTimeout, clearTimer = clearTimeout, adapter = rootedFileAdapter}) {
|
||||
if (!Array.isArray(items) || !items.length) throw new TypeError('A loaded media collection is required');
|
||||
const accepted = Array.isArray(items) ? items.filter(item => openable(adapter, item)) : [];
|
||||
if (!accepted.length) throw new TypeError('A loaded media collection is required');
|
||||
const keys = new Set();
|
||||
const loaded = Object.freeze(items.map(item => {
|
||||
adapter.validate(item);
|
||||
const loaded = Object.freeze(accepted.map(item => {
|
||||
const key = adapter.key(item);
|
||||
if (keys.has(key)) throw new TypeError('Duplicate viewer identity');
|
||||
keys.add(key);
|
||||
|
||||
Reference in New Issue
Block a user