Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

medcharrafi's avatar

Issues with Managing Multiple Instances of a CodeMirror-Based File Editor in Alpine.js & Livewire

I'm working on a Livewire component that includes a repeater functionality for managing multiple file inputs, each with a CodeMirror editor embedded in an Alpine.js component. Here's a summary of my setup:

Create.php (livewire component class):

Blade View Of The Class :

The Blade view loops through the files collection, rendering each file with a unique uuid. The file-editor is a custom Blade component that initializes the CodeMirror editor.

File editor component

The file-editor Blade component initializes the Alpine.js editor component, passing the necessary props such as uuid, content, and language.

the alpine editor component

The Alpine.js editor component is responsible for initializing the CodeMirror editor and updating the Livewire component with the editor's content.

The Problem

When I have one instance of the component on the page, everything works perfectly. However, when I add multiple instances (since this is a repeater component), only the latest instance of the file editor works, while the others do not. I've ensured that each x-ref is unique by appending a UUID to it, but the issue persists.

0 likes
1 reply

Please or to participate in this conversation.