Skip to content

Clean up IndexedDB previous-page listener - #55

Closed
issackjohn wants to merge 1 commit into
mainfrom
fix-indexeddb-page-listener
Closed

Clean up IndexedDB previous-page listener#55
issackjohn wants to merge 1 commit into
mainfrom
fix-indexeddb-page-listener

Conversation

@issackjohn

@issackjohn issackjohn commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary

Rework how the DeletingAllItems step waits for the IndexedDB TodoMVC app to finish a
previous-page navigation.

Problem

The step kept its promise resolver as a property hung off the iterationFinishedListener
function object, and registered a previous-page-loaded listener that was never removed:

  • The resolver was shared mutable state on a function, so which promise a given event
    resolved depended on loop ordering rather than being explicit.
  • The listener outlived the step, since nothing ever called removeEventListener.
  • A promise was allocated on every one of the 10 iterations, even though the last iteration
    never navigates and never awaits it.

Change

Add a module-scope waitForPreviousPageLoaded() helper that returns a promise backed by a
{ once: true } listener, and call it immediately before clicking the Previous button.
Each page transition now owns its own listener and resolver, and the listener removes itself
once the event fires.

previous-page-loaded is dispatched only from todo-app's moveToPreviousPage(), which
runs only in response to the bottombar's previous-page event from that button click. So
registering the listener just before the click cannot miss the event or observe a stray one.

This is a refactor of the benchmark's synchronization only. The measured work is unchanged.

Notes

dist/src/workload-test.mjs is regenerated from src/workload-test.mjs by
npm run build in suites-experimental/javascript-wc-indexeddb; both are updated here so
the checked-in build stays in sync.

Validation

  • npm run test:node — 66 passing, including the resources.txt validity check
  • eslint and prettier --check clean on the changed source

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR cleans up the IndexedDB TodoMVC benchmark’s “previous page loaded” synchronization by replacing a shared, hidden promiseResolve function property with a per-transition one-shot promise tied to the previous-page-loaded event. This makes page-transition waiting deterministic (listener installed immediately before the click) and ensures the listener is automatically removed after firing.

Changes:

  • Replace the persistent previous-page-loaded listener + iterationFinishedListener.promiseResolve state with waitForPreviousPageLoaded() that uses addEventListener(..., { once: true }).
  • Register the listener immediately before clicking the previous-page button, then await the resulting promise.
  • Apply the same update to both the source and generated dist workload test files.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
experimental/javascript-wc-indexeddb/src/workload-test.mjs Switches “previous page loaded” waiting logic to a per-iteration one-shot promise to avoid missed events and hidden listener state.
experimental/javascript-wc-indexeddb/dist/src/workload-test.mjs Keeps generated dist workload test in sync with the updated source behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The DeletingAllItems step stored its resolver as a property on the
iterationFinishedListener function object, and registered a
previous-page-loaded listener that was never removed.

Replace it with a waitForPreviousPageLoaded() helper that registers a
one-shot listener per page transition, so the resolver is scoped to the
navigation it belongs to and the listener removes itself once the event
fires.
@issackjohn
issackjohn force-pushed the fix-indexeddb-page-listener branch from 4ad12d3 to d31cc45 Compare July 24, 2026 23:40
@issackjohn
issackjohn changed the base branch from responsive-design to main July 24, 2026 23:40
@issackjohn issackjohn closed this Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants