Faith Forge LabsPeru

Three correct product cards, one wrong question target

The catalogue shows three different products with the right names and documents. Yet selecting “Ask about this item” on any card opens a question for the last product in the list.

This fictional investigation uses an older JavaScript component and a test question receiver. The cause is the state captured by each event callback, rather than the source records or a rearranged list. No operational buyer messages are sent.

Record the visible and receiving identities

The three approved fixtures are P-31, P-32 and P-33. Each card displays its own name and approved specification. The reviewer opens them individually and confirms that the displayed information belongs to the intended record.

The question buttons behave differently. P-31’s button prepares P-33; P-32’s button also prepares P-33; P-33’s button prepares P-33. The last result looks correct, so testing only that card would miss the defect.

The source list has not been sorted or filtered between display and activation. The cards’ explicit record attributes are correct. Replacing a row number with another row number would not resolve this evidence.

Follow what the callbacks actually read

The inspected component uses a loop to create its buttons. A function-scoped variable is assigned the current product on each iteration. Each callback refers to that same variable, but the callbacks execute later, after the loop has finished.

At activation time the shared variable holds P-33, its final assignment. All three callbacks therefore read P-33 even though their labels were rendered earlier from the correct iteration values.

JavaScript functions retain access to bindings in their surrounding environment. The ECMAScript environment model describes those bindings; the critical distinction here is between sharing one mutable binding and giving each action the intended value in its own binding.

The developer traces the callback argument at the point the question is prepared. That establishes the cause without changing the product database or trying to make every card display P-33 so the result appears consistent.

Make the action’s record explicit

The repair creates each handler with its intended stable product identifier in a separate binding. In the inspected implementation, a small handler factory receives the current identifier as an argument and returns the callback. Each factory invocation has its own parameter binding.

When activated, the callback uses that identifier to request the permitted question context through the existing application route. It does not retain a mutable global “current product” as the authority for which item the user selected.

The receiver still checks the identifier and the user’s permission. A correct callback argument is useful context, not a substitute for receiving validation. Unknown or disallowed records must not become accessible because a button supplied their identifier.

Replay the selections in a different order

The isolated review activates P-32 first, then P-31, then P-33. The prepared questions and test receiving records identify P-32, P-31 and P-33 respectively. Each includes the expected approved document relationship.

Activated card Prepared question target Source record changed?
P-32 P-32 No
P-31 P-31 No
P-33 P-33 No

The reviewer then returns to P-31 after visiting the others. Its button still identifies P-31. This distinguishes a per-action binding from another shared variable that merely follows the most recently visited card.

An unrelated editor action retains its original target and permission checks. A direct attempt to request an unknown identifier is rejected by the receiving fixture. Product names, document identities and source order remain unchanged throughout.

Keep the acceptance question about the whole action

A button label can be correct while its operation is wrong. The acceptance review must follow the activated control into the prepared question and the receiving record. Looking only at the rendered card leaves the important boundary untested.

The fixture does not require replacing the catalogue or abandoning event-driven interfaces. It supports a bounded change in how this component binds record identity. Other callback code may warrant inspection, but it is not automatically declared faulty from this one finding.

The handover includes all three source IDs, the original shared-binding cause and the reordered activation sequence. A future maintainer can reproduce the distinction without relying on a customer’s recollection that “sometimes it asks about the wrong thing”.

For the larger catalogue task, the product information service follows identity from the approved record through presentation and the customer’s actual question.