volt icon indicating copy to clipboard operation
volt copied to clipboard

Volt components do not support namespacing, causing conflicts across modules with same component names

Open eliofery opened this issue 7 months ago • 7 comments

Volt Version

1.7

Laravel Version

12

PHP Version

8.4

Database Driver & Version

No response

Description

In my Laravel project, I follow a modular structure where each module can have its own set of Livewire components. It’s common for different modules to have components with the same name (e.g., Button), and Livewire allows for namespacing to prevent conflicts:

class Button extends Component
{
    public function render()
    {
        return view('somemodule::livewire.button');
    }
}

Then in the Blade view, I can use:

<livewire:somemodule::button />

This works perfectly and avoids naming collisions.

However, when using Volt components, the render() method is not defined, and as a result, I cannot specify a view path or namespace. Volt components are always referenced like:

<livewire:button />

If multiple Volt components with the same name exist across different modules, one of them overwrites the others. This makes it impossible to use the same component name in different modules when using Volt.

Steps To Reproduce

  1. Create a Laravel modular project structure.
  2. In ModuleA, create a Volt component named Button.
  3. In ModuleB, create another Volt component also named Button.
  4. Attempt to reference both components in a Blade file (components will not be found):
<livewire:module-a::button />
<livewire:module-b::button />
  1. Observe that only one of the components is registered and used, due to lack of namespacing in Volt.
<livewire:button />

eliofery avatar May 20 '25 16:05 eliofery

I've made a package that adds support for namespaces, use at your own risk though: https://github.com/ganyicz/volt-namespaces

ganyicz avatar May 31 '25 15:05 ganyicz

I've made a package that adds support for namespaces, use at your own risk though: https://github.com/ganyicz/volt-namespaces

Thanks for your work. I will test it.

eliofery avatar Jun 02 '25 15:06 eliofery

Native support for namespacing would be great. @ganyicz thanks for the work!

mauritskorse avatar Jul 08 '25 11:07 mauritskorse

@ganyicz are you willing to propose your package as a PR? It is a useful feature for those working with a modular approach.

robsontenorio avatar Sep 28 '25 23:09 robsontenorio

@ganyicz are you willing to propose your package as a PR? It is a useful feature for those working with a modular approach.

Probably not, Livewire 4 adds native namespace support and Volt is going get sunsetted, I think the package is an okay solution for those who need backwards compatibility

ganyicz avatar Sep 29 '25 05:09 ganyicz

@ganyicz you said “ Volt is going get sunsetted” ??

Where can I see more about this ?

robsontenorio avatar Sep 29 '25 16:09 robsontenorio

@ganyicz you said “ Volt is going get sunsetted” ??

Where can I see more about this ?

Single file components are going to be supported by default in Livewire 4.

Check out Caleb's talk from this year's Laracon: https://youtu.be/M60-nxlrePc?si=D-flzeoEqGSiT933

ganyicz avatar Sep 29 '25 16:09 ganyicz