A list that re-renders every second only loses state when each tick throws its rows away and builds new ones. In React that means a key that changes, an index key on a list that reorders, or a row component defined inside its parent. The fix is the same everywhere: a tick updates values in place, and the list is rebuilt only when its shape changes. We shipped the plain-DOM version of this bug in our own authenticator, and a secret on screen lasted under a second.

The bug: a setup key that lasted under a second

The companion is the extension inside every Mosaic profile's browser. On 29 September 2026 it got an Auth panel: two-factor codes saved on the profile, each row with the six digits, a ring that empties over the code's step, usually 30 seconds, and a Key button that swaps the sub-line for the setup key, so you can copy it into another authenticator at your own pace.

The panel refreshed once a second, because the ring has to move and the digits change on the step. The first version did the obvious thing on each tick: clear the list and draw every row again from the data.

It looked right in every screenshot. Then we pressed Key. The setup key appeared, and the next tick, at most a second later, drew a fresh row that knew nothing about the button and showed the sub-line again. The secret flashed and vanished. A person trying to copy it had less than a second, and the whole point of showing it is that it can be read at leisure.

We found it by driving the popup over the DevTools protocol and reading what it actually drew, which is how every fault in that panel was found. Nothing in the source looked wrong.

Why a tick that rebuilds discards state

The revealed key was not in the data. It was in the row: a sub-line swapped by a click handler. Rebuilding the row from the data rebuilt it without the thing the reader had put there.

Any per-row state that is not in the model goes the same way: an open menu, a half-typed input, a text selection, focus, the scroll position inside a cell, a CSS transition halfway through. A timer that rebuilds takes all of them, once a second, and a list that rebuilds only on a user action hides the same bug until somebody adds a clock.

Each profile keeps its own passwords and its own 2FA codesIn Mosaic: Logins and 2FA codes. A password vault and TOTP codes for each profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

How it works: Logins and 2FA codes

How we fixed it: update in place, rebuild on shape

The panel now keeps a short string describing what the rows are, not what they say:

ids of the visible rows, each marked if its key is shown, plus the filter

On each tick it computes that string again. If it matches the last one, nothing structural has happened, so the tick touches only the digits and the ring on rows already on the page (and adds an expiring class in the last five seconds, because copying a code then is how people paste one that has just expired). If it differs (a code was added or removed, the search filter changed, a key was revealed), the list is rebuilt.

A code changing every 30 seconds is not a change of shape. A key being revealed is, because that row is laid out differently.

The second half is where the flag lives. Which keys are on screen is held in a set of credential ids, outside the rows. That survives the tick, survives a reload of the list from the profile, and survives a row being filtered out and back in. It is deliberately not saved: it resets when the popup closes, which is the one moment nobody is looking at it.

Why a React list loses state when it re-renders

React does the in-place half for you. Its docs say it "will keep the state around for as long as you render the same component at the same position in the tree", and a key decides which item is which. So a list re-rendered every second keeps its rows' state, unless something tells React they are new rows. Three things do:

  1. A key that changes. key={entry.id + entry.code} looks unique and is new every 30 seconds, so the row remounts on the step. key={Math.random()} is new every tick; React's docs say it causes "all your components and DOM being recreated every time" and that it "will also lose any user input inside the list items". Their rule is short: "Keys must not change or that defeats their purpose!"
  2. An index key on a list that moves. If the sort changes or a row is inserted above, index 2 is now a different item, and it inherits the previous item's state.
  3. A row component defined inside the parent. A function declared in the parent's body is a new component type on every render, so React destroys the old one. The docs list it as a pitfall: "This is why you should not nest component function definitions."

Then put revealed or expanded flags where our set of ids is: in the parent, keyed by the item's id, not inside the row.

const [shown, setShown] = useState(() => new Set())

{entries.map((e) => (
  <CodeRow
    key={e.id}
    entry={e}
    revealed={shown.has(e.id)}
    onToggle={() => setShown((s) => {
      const next = new Set(s)
      next.has(e.id) ? next.delete(e.id) : next.add(e.id)
      return next
    })}
  />
))}

A stable key={e.id} keeps the row mounted while its digits change. The flag lives above the row, so even a row that does remount (filtered out and back) comes back revealed.

Where this lives in Mosaic

The Auth tab is in the companion of every profile, and the codes on it belong to that profile alone: they sit in its credential vault and get typed into the site's form with real keystrokes (logins and 2FA codes per profile). An agency with forty clients sees forty separate lists, one per window, and managing 2FA codes for multiple accounts covers how that is set up.

The panel had a second fault the same day. Opened from full screen it drew nothing at all, because a call at the top of the generated script ran before a const it reached for had been evaluated (a top-level call that killed the popup).

Sources

  1. React: Preserving and Resetting State, read November 3, 2026
  2. React: Rendering Lists, read November 3, 2026