A small module loads a ticket summary by string identifier and returns state for a console panel. After a recent PR, the behavior became unstable: for some errors the module reports a successful result, and repeated requests start affecting one another.
createTicketSummaryLoader export must return an object with a load(ticketId: string) method.load accepts a ticket identifier, normalizes it with trim(), and works only with a non-empty value.status: "idle"ticket: nullerror: nullstatus: "ready"ticket with fields id, title, requestererror: nullload must return an error state:
status: "error"ticket: nullerror with the message textload call must not allow external code to change internal cache data through the returned object.const loader = createTicketSummaryLoader(async (id) => {
if (id === "A-1") {
return { id: "A-1", title: "Printer outage", requester: "Mila" };
}
if (id === "BAD") {
return { id: "BAD", title: "Broken shape", requester: 42 };
}
throw new Error("gateway timeout");
});
await loader.load("A-1"), then modify the returned object:const first = await loader.load("A-1");
if (first.ticket) {
first.ticket.title = "Changed outside";
}
const second = await loader.load("A-1");
await loader.load("BAD")."A-1" must still contain the original title, not the external mutation.requester: 42 must not be considered successful.ticket.status: "error", without replacing the result with a successful state.22.x5.8ES modulesstrict: truenode after building with tsc(ticketId: string) => Promise<unknown>Use line comments to explain the problem, its impact, the fix and how to test it.