Skip to content

Laravel url helper returns incorrect root url in wp-admin (affects Livewire v4.0 scripts) #495

@kevinlisota

Description

@kevinlisota

Version

v5.0.5

What did you expect to happen?

When using Livewire on some pages I created inside of wp-admin, the @livewireScripts command outputs a script URL that references the routes generated by Livewire. The output of @livewireScripts should result in a URL like https://mydomain.com/livewire/livewire.min.js.

What actually happens?

In the new version of Livewire v4, they are now using the Laravel url() helper to generate URLs. In v3, they used a root-relative path. Inside of wp-admin, the Laravel url() function returns https://mydomain.com/wp-admin/admin.php, which is the page URL I'm using, not the root URL. I briefly tested the front end, and url() appears to work correctly there, so likely something related to wp-admin. Here is a link to the discussion on the Livewire repo.

The result is that @livewireScripts renders URLs (and update URLs) that don't match the Livewire routes. Instead of https://mydomain.com/livewire/, we get https://mydomain.com/wp-admin/admin.php/livewire/.

Steps to reproduce

  1. Install Livewire v4
  2. Render @livewirescripts inside of wp-admin, either in the footer or in a template.
  3. Compare the rendered URLs to the Laravel route table and note the mismatch.

System info

No response

Log output

Please confirm this isn't a support request.

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions