Skip to content

Global Elements: Workspace hotfix for 'Unique is missing' warning#22935

Merged
AndyButland merged 1 commit into
release/18.0from
v18/hotfix/element-workspace-error
May 21, 2026
Merged

Global Elements: Workspace hotfix for 'Unique is missing' warning#22935
AndyButland merged 1 commit into
release/18.0from
v18/hotfix/element-workspace-error

Conversation

@leekelleher

Copy link
Copy Markdown
Member

Description

In the 18.0-beta, when navigating between Element workspaces in the Library section, the following error fired:

element-publishing.workspace-context.ts:473 Uncaught (in promise) Error: Unique is missing
    at #loadAndProcessLastPublished (element-publishing.workspace-context.ts:473:22)
    at Object.next (element-publishing.workspace-context.ts:442:11)

This was due to a race condition between the unique observable and the getUnique() guard in the entity-detail workspace base.

This PR resolves this by falling back to #currentUnique, as this is kept up-to-date from the unique observable.

@claude

claude Bot commented May 21, 2026

Copy link
Copy Markdown

Claude finished @leekelleher's task in 1m 59s —— View job


PR Review

Target: origin/release/18.0 · Based on commit: 4186ba8ce3e43a4663df18ce17eeaae4704df0fe

Fixes a race condition in #loadAndProcessLastPublished() where getUnique() transiently returns undefined during the window between the unique observable emitting a new value and _getDataPromise being set in the base workspace context, by falling back to #currentUnique (kept synchronously up-to-date from the same observable).


Suggestions

  • element-publishing.workspace-context.ts:472–474: The comment references _getDataPromise — a private field in entity-detail-workspace-base.ts — which isn't visible from this file. Readers who aren't familiar with the base class will have to hunt for it. Consider replacing the parenthetical with a link or a more self-contained description, e.g. "…data loading starting (the workspace hasn't begun fetching yet)." The core explanation is still useful; this is purely a readability note.

  • element-publishing.workspace-context.ts:466: No test added for the race condition. Given the async/observable nature of the bug, a deterministic unit test is admittedly hard to write, but a controller-level test that calls #loadAndProcessLastPublished (or an exported equivalent) while mocking getUnique() to return undefined and #currentUnique to hold a value would document the contract and guard against future regressions.


Approved

The fallback is safe: #currentUnique is assigned synchronously on the line immediately before #loadAndProcessLastPublished() is called in the observer (line 439 → 442), so the value is always available when this race fires. The getIsNew() guard before the lookup ensures new elements are still skipped. The fix is minimal, correct, and doesn't touch any public API surface.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a race condition in the Elements publishing workspace context that could throw Error: Unique is missing when navigating between Element workspaces (notably in the Library section) during 18.0-beta. The fix ensures the pending-changes/published-data logic can resolve an entity unique even in the short window where getUnique() intentionally returns undefined before _getDataPromise is set.

Changes:

  • Update #loadAndProcessLastPublished() to fall back to the locally tracked #currentUnique when getUnique() returns undefined.
  • Add inline comments clarifying why getUnique() may return undefined and why #currentUnique is a safe fallback in this context.

@AndyButland AndyButland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've tested this locally and confirmed I could see the error before the fix and no longer after.

Will merge in as the failing unit tests are not related.

@AndyButland AndyButland merged commit 73195ca into release/18.0 May 21, 2026
25 of 29 checks passed
@AndyButland AndyButland deleted the v18/hotfix/element-workspace-error branch May 21, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants