Skip to content

Route livewire/wire-spy.min.js not registered correctly? #29

@LucianoVandi

Description

@LucianoVandi

Environment:

  • Laravel version: 11 (upgraded from v10, old directory structure)
  • Livewire version: 3.5.12
  • wire-elements/wire-spy version: 0.0.9
  • PHP version: 8.2

The route for livewire/wire-spy.min.js defined in the SupportAutoInjectedAssets::provide() method, does not seems to register correctly, causing a 404 error when accessed. After investigating, I found that this issue could be related to the timing of when the route is registered within the application's lifecycle.

After adding logging in SupportAutoInjectedAssets::provide(), I noticed that the method is called before the application has fully registered all routes, which prevents the route from being accessible. However, modifying the route registration in provide() to use App::booted resolves the issue:

class SupportAutoInjectedAssets extends ComponentHook
{
    public static function provide()
    {
        App::booted(function(){
            Route::get('livewire/wire-spy.min.js', function () {
                return response(file_get_contents(base_path('vendor/wire-elements/wire-spy/dist/wire-spy.min.js')))
                    ->header(key: 'content-type', values: 'application/javascript');
            });
        });
    ....

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions