Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/estepper-layout-module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sourceacademy/web-e-stepper": patch
---

e-stepper: the arrangement of the panes and the divider survive a Run (the host makes a new plugin on every Run, and calls the bundle's factory again, so they are kept for the page on `globalThis`)
11 changes: 9 additions & 2 deletions src/web/e-stepper/src/EStepperHostPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ import EStepperView, { type PaneLayout } from "./EStepperView";
/** The side-content tab id used by the host to show/hide the e-stepper tab. */
const TAB_ID = "e-stepper";

/**
* The user's arrangement of the panes, kept on `globalThis` for the page. Neither the plugin nor this
* module will do: the host terminates the conduit and makes a new plugin on every Run, and the
* bundle is wrapped in a factory (see `wrap.mjs`) that the host calls again each time, so even a
* module-level variable is new on every Run. The divider is to stay where the user put it.
*/
const LAYOUT_KEY = Symbol.for("sourceacademy.e-stepper.layout");
const layout: PaneLayout = ((globalThis as Record<symbol, unknown>)[LAYOUT_KEY] ??= {});

interface State {
steps: EStepperStep[];
profile?: SyntaxProfile;
Expand Down Expand Up @@ -65,8 +74,6 @@ export class EStepperHostPlugin implements IPlugin {

const subscribe = (listener: () => void) => this.subscribe(listener);
const getState = () => this.getState();
// Kept here, not in the view: a run may mount the view anew, and the user's divider stays.
const layout: PaneLayout = {};
const cseDiagram: ICseDiagramService | undefined = hostServices?.cseDiagram;
function EStepperTab() {
const state = useSyncExternalStore(subscribe, getState);
Expand Down
Loading