1 pointby vortexshadow3 hours ago4 comments
  • vortexshadow2 hours ago
    To add some context: I’m specifically thinking about cases where each individual state update looks valid on its own, but the combination over time breaks a business rule.

    For example, async flows where status updates and data creation are handled in different places.

    Curious how teams make these kinds of assumptions explicit in practice.

  • vortexshadowan hour ago
    One nuance I keep seeing is that each individual update is valid, but the invariant only breaks after a specific sequence of events.

    That’s where things get tricky to reason about upfront.

  • al_borland2 hours ago
    Wouldn’t this be a gap in the tests that needs to be closed?
    • vortexshadow2 hours ago
      Tests definitely help, and I agree they should cover as much logic as possible.

      The gap I’ve seen is that tests usually validate expected scenarios, while some invariants only break after specific sequences of events or over time — especially with async flows and state that evolves across renders.

      In practice, we found tests and runtime checks to be complementary: tests verify intent, invariants catch unexpected drift when reality doesn’t match assumptions.

  • OsrsNeedsf2P2 hours ago
    Fail as early as possible. In this specific case, invariants help.
    • vortexshadow2 hours ago
      Exactly.

      Failing early is the key part — especially before invalid state has a chance to propagate through the system.

      What I’ve found tricky in React apps is identifying where those invariants should live when the logic spans multiple async updates.

      Do you usually enforce them close to state updates, or at higher-level boundaries?