squiggle icon indicating copy to clipboard operation
squiggle copied to clipboard

Seed reset shouldn't lose collapse/expand state

Open berekuk opened this issue 1 year ago • 1 comments

berekuk avatar Nov 20 '24 14:11 berekuk

This is complicated.

On seed reset, the playground re-renders with the new environment, which causes this code in useSimulator to return undefined:

  const output = project.hasHead(renderedHeadName)
    ? project.getOutput(renderedHeadName)
    : undefined;

(the head is there, but project.getOutput looks for the output based on the hash(module, environment) with new environment, so output is not there)

Because the output is missing, the playground renders the right panel without the viewer, and so without the ViewerProvider, and its state gets lost.

There might be several ways to fix this, but the one that looks the least like a workaround to me is to implement per-head environments in SqProject. I don't remember the details, but I remember it's not trivial, see e.g. this comment:

https://github.com/quantified-uncertainty/squiggle/blob/2e58df42fccdb03b683a855680f4ec336c2155d1/packages/squiggle-lang/src/public/SqProject/ProjectState.ts#L75-L78

berekuk avatar Jan 14 '25 18:01 berekuk