Skip to content

Fix asset editors crashing when the container has no site#127

Open
jakobploens wants to merge 1 commit into
statamic:masterfrom
jakobploens:fix/asset-editor-undefined-site
Open

Fix asset editors crashing when the container has no site#127
jakobploens wants to merge 1 commit into
statamic:masterfrom
jakobploens:fix/asset-editor-undefined-site

Conversation

@jakobploens

Copy link
Copy Markdown

Problem

On Statamic 6, opening any asset editor throws and the editor's fields never render:

Uncaught (in promise) TypeError: can't access property "replaceAll", this.container.site.value is undefined

Assets aren't site-scoped, so the asset publish container has no site. Workspace.initializeEcho() builds the channel name as:

this.channelName = `${reference}.${this.container.site.value.replaceAll('.', '_')}`;

container.site.value is undefined for assets → .replaceAll throws during workspace init (a mounted hook), aborting the editor render. Reproduces on every asset container in a single-site install.

Fix

Build the channel without the site segment when no site is present (and use optional chaining). Entries/terms (which have a site) are unchanged; assets now get a stable, site-less presence channel keyed by their reference instead of crashing.

const reference = this.container.reference.value.replaceAll('::', '.');
const site = this.container.site?.value;
this.channelName = site ? `${reference}.${site.replaceAll('.', '_')}` : reference;

Fixes #126.

Assets aren't site-scoped, so an asset publish container's `site.value` is
undefined. initializeEcho() called `.replaceAll` on it unconditionally,
throwing in the workspace init (a mounted hook) and preventing the asset
editor from rendering its fields.

Build the channel name without the site segment when no site is present
(and use optional chaining), so asset editing works and assets still get a
stable presence channel keyed by their reference.

Fixes statamic#126
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Asset editors crash on Statamic 6: container.site.value is undefined (assets have no site)

1 participant