DevPath
Senior lesson · 16 min

Keep several async views consistent

Coordinate cache, invalidation, and optimistic updates without hiding uncertainty.

Choose the source of truth

A jobs list, detail page, and saved-items count may all display the same record. Decide whether the server, a client cache, or local component state owns each value. A mutation should update or invalidate every affected view. Otherwise a successful save can appear undone when navigating back.

Use optimistic updates carefully

An optimistic bookmark can feel immediate, but the UI must reverse it if the server rejects the write. Keep the previous value so rollback is exact. For a payment or application status, avoid pretending success before confirmation; show a pending state and reconcile with the server.

const previous = cache.get(jobKey);
cache.set(jobKey, { ...previous, saved: true });
try { await saveJob(id); }
catch { cache.set(jobKey, previous); }

Test conflicting timelines

Run two quick mutations, let responses arrive out of order, and verify the final view reflects the latest confirmed state. Test a failed mutation after an optimistic update and a reload from another tab. Name the consistency promise in product terms so users know whether a change is saved or still pending.

Check your understanding

When should a UI avoid optimistic success?

Show explanation

When the action has a consequential or uncertain external effect, such as a payment; show pending until the server confirms it.

Try it at senior level

Design an optimistic edit shown in a list, detail view, and cached summary. Walk through success, validation failure, and network timeout.

Check your work

All three views converge on one server state, rollback is scoped to the edit, and uncertainty is shown instead of hidden.

Self-guided practice. This does not record assessed mastery.

Put this lesson into practice

A related activity in this module at mid level.

Try: Cancel outdated search requests

Further reading

Primary references for this module. Check the current version when behavior or framework guidance may have changed.