Skip to content

refactor: replace the $root event bus with mitt - #3848

Open
Vondry wants to merge 2 commits into
bolt:6.2from
Vondry:refactor/mitt-event-bus
Open

Vondry wants to merge 2 commits into
bolt:6.2from
Vondry:refactor/mitt-event-bus

Conversation

@Vondry

@Vondry Vondry commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Next step in splitting #3751 towards Vue 3.

Why

The Text and Slug fields keep the slug in step with the title by sending events over this.$root.$emit/$on. Vue 3 removes $on/$off/$once, so this link breaks on upgrade whatever else is ready.

Why mitt

  • It is the replacement the Vue 3 migration guide recommends
  • It works the same on Vue 2.7 and Vue 3, so it can land now without touching the rest of the migration.
  • It is about 200 bytes with no dependencies, and typed, so the events and their payloads are declared in one place.

What changed

  • assets/js/app/eventBus.ts holds the bus, with the same events and payloads as before. Behaviour is unchanged.
  • Text and Slug use it, and unsubscribe when destroyed; the $root listeners were never removed.
  • SlugTextIntegration.spec.ts covers the slug ⇄ title flows end to end, as a baseline for the Vue 3 port.

Afterwards, the only bus change left for #3751 is beforeDestroy → onBeforeUnmount.

Note for extensions: a script emitting these events on the editor's $root no longer reaches the fields. Vue 3 removes $root.$emit anyway.

Testing

mitt_event_bus_slug_scenarios

Vue 3 removes $on/$off/$once, so Text and Slug can no longer talk over
$root. They now use a typed mitt bus, which works the same on Vue 2.7 and
Vue 3. Events and payloads are unchanged.

Both components now unsubscribe before they are destroyed; the $root
listeners were never removed.
Mounts Slug and Text side by side over the real event bus, so the link
between them is covered end to end: a new record's slug follows its
title, and so does a localised record's while its title is empty. An
existing one does not until it is generated, Edit or Locked stops it,
and generating again resumes it. A slug built from several fields joins
them, and removing a text field elsewhere, as a collection re-render
does, leaves the link intact.
@Vondry
Vondry force-pushed the refactor/mitt-event-bus branch from ff7930e to 64ae3cd Compare October 26, 2026 09:59

This branch has not been deployed

No deployments
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.

1 participant