Workspace Initialization Race Condition Fix & Preview Recovery

Workspace Initialization Race Condition Fix & Preview Recovery

When opening Open Publisher or creating a new publication from the Startup Dashboard, the workspace canvas should load smoothly and display a crisp page preview in the left navigation sidebar. In earlier builds, an asynchronous race condition during document bootstrap could corrupt new sessions: closing the dashboard or creating a new document could trigger a history save before the page DOM was fully assembled, resulting in unwanted "phantom" pages, empty sidebar previews, or corrupted page sizes. Version 4.19.7 resolved these initialization conflicts with strict empty workspace guards and session index resets.

🛠️Clean Document Workspace Initialization with Active Page Preview

op WorkspaceInitializationRaceConditionFixAndPreviewRecoveryNew publications initialize with verified document geometry and instant page thumbnail preview generation.

The Premature History Snapshot Bug

The primary cause of phantom pages and corrupted previews was traced to early history capture:

  • The Empty Workspace History Save: During document startup, setPageSize() was invoked to establish initial dimensions. However, setPageSize() unconditionally triggered pushHistory(), capturing a snapshot before the initial page was rendered.

  • Phantom Page Creation: Saving an incomplete state object into the undo/redo stack caused the history engine to treat the empty initialization state as "Page 1" and the subsequent rendered document as "Page 2", creating duplicate phantom entries.

  • Empty Workspace Guard: In layout/document.js, setPageSize() is now guarded against executing pushHistory() when the workspace is completely empty during initialization.

Dashboard startBlank Index Safety Reset

Session initialization was hardened to prevent index collision:

  • Stale Index Resolution: In earlier versions, creating a new document could retain a stale currentPageIndex from a previous session, causing newly created pages to reference invalid slot offsets.

  • Explicit Index Re-Zeroing: Added an explicit safety reset for currentPageIndex = 0 inside the dashboard's startBlank workflow, ensuring every new document starts from a clean zero index.

Thumbnail Preview Recovery

By preventing premature history snapshots and index corruption, sidebar thumbnail previews generate accurately upon session start, displaying correct page dimensions and background styling across all browsers without requiring manual page refresh.

Tip: If you ever need to reset your workspace to a clean state, you can click "New Document" in the File menu or press Ctrl+N.