Skip to content

Remove unused dependencies #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

depsimon
Copy link

axios is not used anymore.
I suspect this is a leftover of the original starter kit which uses axios.

autoprefixer is not used anymore.
It was used as as PostCSS plugin, but as it's been replaced by the Vite plugin it's not needed anymore.

@vanm
Copy link
Contributor

vanm commented Mar 30, 2025

Good find

Copy link
Contributor

@tnylea tnylea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right you are. Thanks to Livewire we no longer need Axios.

Appreciate it 👏

@tnylea tnylea added the Approved Approved for Merge label Mar 31, 2025
@taylorotwell
Copy link
Member

I'm a bit curious if Echo would fail if Axios is removed.

@taylorotwell taylorotwell marked this pull request as draft April 1, 2025 15:05
@depsimon
Copy link
Author

depsimon commented Apr 1, 2025

I'm a bit curious if Echo would fail if Axios is removed.

It should not as laravel-echo is not dependant on axios.
I just tested to be 100% certain, and I managed to get the messages broadcasted to the frontend. You can check it out on this branch with a valid PUSHER config in .env

@taylorotwell
Copy link
Member

@depsimon did you try with a private channel that would hit the broadcasting authentication route?

@vanm
Copy link
Contributor

vanm commented Apr 9, 2025

I was curious to follow this thread and did some exploring:

Here's the docs for laravel-echo (now under Broadcasting in the main Laravel docs) and it does mention expecting axios to be imported (otherwise the implementor will need to configure sending their own headers).

Echo implements a pattern where it registers "third party request interceptors" so it can add the header to each request, and it looks for the existence of Axios (or alternatively, Vue.http, jQuery, or Turbo): https://github.com/laravel/echo/blob/f333d49d116fcd7302d1fd19815b6876ce542085/src/echo.ts#L159

So it's a soft dependency, in a way - and a documented one. If someone is configuring Echo, they will need to use either one of these libraries or send the header themselves. So, by including Axios in the starter kit, it enabled this sort of soft dependency to work for packages like Echo.

There's no right answer for what to do here, but it was interesting to follow Taylor's comments and see why Axios might be expected down the line.

Since this is a starter kit and there are many steps required in order to configure Broadcasting, there's a case to be made that the axios dependency doesn't need to be enforced in this starter kit and instead the implementor could make their choice down the line if they chose to install Echo. On the flip-side, Axios is useful and may make sense to include as a suggested front-end library, and has the benefit of meeting these downstream soft dependencies (it wouldn't make sense for Echo to depend formally on one of the many front-end libraries, so I understand why it implemented the "check and inject" pattern to play well with whatever the implementor decided. Since it's documented, it's not a huge mystery for those configuring Echo.

All that said, if Livewire itself also requires Axios and implements a similar pattern of injecting headers then it makes sense for this starter kit. If that’s the case, where would that be?

@vanm
Copy link
Contributor

vanm commented Apr 9, 2025

Some more cursory digging, since I've never looked at the Livewire code before I decided to take a peek:

Laravel Echo support is framed as optional for Livewire:
https://github.com/livewire/livewire/blob/403eb7dd518b837b9f99d599341883e28d9e489a/docs/events.md?plain=1#L412

If Echo is detected (window.Echo), the X-Socket-ID header is added to requests:
https://github.com/livewire/livewire/blob/403eb7dd518b837b9f99d599341883e28d9e489a/js/features/supportLaravelEcho.js#L4

So it seems like Livewire will play nice with Laravel Echo if the project decides to use it, and the header will be added.

Livewire itself uses the native window.fetch API to send requests, and does not rely on Axios.

It seems like people would only need to add Axios (or an alternative supported library) if they wanted to install Echo, and since Echo is not configured by default for this starter-kit (and the dependency is documented in the Echo installation guide), Axios could be removed from this project. If there's something else that's undocumented or I am missing something, let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved Approved for Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants