Skip to content

Conversation

@kube
Copy link
Collaborator

@kube kube commented Jan 15, 2026

🌟 What is the purpose of this PR?

This PR removes Zustand for State Management.

Zustand was only used for Editor and Simulation (SDCPNContext was already a React context given the PetriNet definition/state is outside of the component).

Performance

React Contexts are a bit slower, but not much now given React Compiler does a lot of optimization of the consumer components. We will optimize performance later when it will make sense to do it, if needed.

Simulation Speed

This PR required to do some rewrite of SimulationProvider in more React-way, and I ended up doing frame generation by batch/budgeting.

So now instead of generating one frame every 20ms (maximum of 50 frames per second), we compute as much frames as we can during 5ms, every 50ms. (10% of main thread time allocated to simulation).

This results in much faster generation speed. (~5000 frames per second in Production Machines example)

This still runs in main thread, but once we move the Simulator in a Web Worker, we will be able to dedicate a thread to Simulation, and should end up with 10x more frames (50000 frames per second).

🔍 What does this change?

  • Every Context has a DEFAULT_CONTEXT_VALUE. This allows to easily isolate components and contexts for testing, without having to provide the whole context.
  • Use use(Context) everywhere, without intermediary hook, to easily identify dependents.
  • Each Context has two files, one for Context and one for Provider.
    The idea being to split Interface/Implementation, and possibly leverage React Contexts as a Dependency Injection mechanism.
    A Context could have multiple Providers in the future. (Will be useful for HASH simulation/live that will have to sync with server)

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

@vercel
Copy link

vercel bot commented Jan 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Review Updated (UTC)
ds-theme Ignored Ignored Preview Jan 21, 2026 0:48am
hashdotdesign Ignored Ignored Preview Jan 21, 2026 0:48am

@github-actions github-actions bot added area/deps Relates to third-party dependencies (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team labels Jan 15, 2026
Copy link
Collaborator Author

kube commented Jan 15, 2026

@cursor
Copy link

cursor bot commented Jan 16, 2026

PR Summary

State management overhaul

  • Introduces EditorContext, SimulationContext, CheckerContext, and restructures SDCPNContext; adds Providers with DEFAULT_CONTEXT_VALUE
  • Removes Zustand stores and tests (editor-store.ts, simulation-store.ts, simulation-store.test.ts), updates all hooks/components to use(Context)
  • Drops zustand dependency and related imports; adjusts ESLint to allow react/jsx-no-constructed-context-values

Simulation execution

  • Reimplements SimulationProvider to run on a timed loop with batched frames (time-budgeted ticks), plus completion notifications

Misc

  • Centralizes Monaco typings to new contexts, updates panels/SDCPN view to new APIs
  • Keeps Sentry error tracker provider; minor cleanup

Written by Cursor Bugbot for commit 4940b5f. This will update automatically on new commits. Configure here.

@graphite-app graphite-app bot requested a review from a team January 16, 2026 09:53
@augmentcode
Copy link

augmentcode bot commented Jan 16, 2026

🤖 Augment PR Summary

Summary: This PR removes Zustand from Petrinaut and migrates editor/checker/simulation state management to plain React Context.

Changes:

  • Removed the Zustand-based editor and simulation stores (and the simulation store tests)
  • Introduced new context modules for SDCPN, Editor, Simulation, and Checker state
  • Reworked providers to expose state+actions via Context values instead of Zustand selectors
  • Updated hooks/components throughout the editor to consume state via use(Context)
  • Adjusted checker logic to provide diagnostics via a dedicated CheckerContext
  • Updated lint config (disabled react/jsx-no-constructed-context-values) and removed zustand from dependencies

Technical Notes: The simulation execution loop is now implemented with component state, refs, and timeouts instead of an external store; ensure the new Context defaults and lifecycle behavior match prior expectations.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

kube added 2 commits January 21, 2026 13:45
…e prop from ToolbarModes, streamlining props for better clarity and maintainability.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

currentlyViewedFrame: 0,
// Keep initialMarking when resetting - it's configuration, not simulation state
}));
};
Copy link

Choose a reason for hiding this comment

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

Inconsistent SDCPN read location may cause stale parameter values

Low Severity

The reset function reads getSDCPN() outside the setStateValues callback (line 361), while the nearly identical initializeParameterValuesFromDefaults function correctly reads it inside the callback (line 250). This inconsistency means reset could compute parameterValues from a stale SDCPN if the definition changes between the function call and when React processes the state update. The comment in initialize explicitly warns against this pattern: "Use functional update to ensure we see the latest state at processing time."

Additional Locations (1)

Fix in Cursor Fix in Web

Merged via the queue into main with commit 83e60ef Jan 21, 2026
44 checks passed
@kube kube deleted the cf/petrinaut-remove-zustand branch January 21, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/deps Relates to third-party dependencies (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

3 participants