The code builds the shipment label preview screen state from a shipment code. After a recent PR, the scenario with fast switching between codes started behaving unstably, and repeated reads of data sometimes affect one another.
shipmentPreview.ts.node --input-type=module
import { createShipmentPreviewModel } from './shipmentPreview.ts';
const delays = new Map([
['A-100', 40],
['B-200', 5],
]);
const api = {
async fetchLabel(code) {
await new Promise((resolve) => setTimeout(resolve, delays.get(code) ?? 0));
return {
code,
recipient: code === 'A-100' ? 'North Hub' : 'South Hub',
tags: ['fragile'],
};
},
};
const model = createShipmentPreviewModel(api);
const first = model.load('A-100');
const second = model.load('B-200');
await Promise.all([first, second]);
console.log(model.screen);
tags array in one result does not change the data received in another call.load calls, the screen should remain in the state for the last requested code.22.x5.8ES modulesstrict=truenode --input-type=moduleUse line comments to explain the problem, its impact, the fix and how to test it.