Skip to content

Refactor browser logging methods to static #59

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

Merged
merged 1 commit into from
Aug 13, 2025

Conversation

inxilpro
Copy link
Contributor

This PR fixes #37

Right now mapJsTypeToPsr3Level and buildLogMessageFromData are instance methods that are effectively called statically, and for some reason the calls to $this are triggering serialization issues with php artisan route:cache. There may be another underlying problem, but a short-term solution is to just make these two methods static.

Other than being a little mismatched code-style-wise, this should be a very safe refactor for the short term.

@amaelftah
Copy link

maybe we can just add a check if the app running in console then we donot register web routes at all

private function registerRoutes(): void
    {
        if ($this->app->runningInConsole()) {
            return;
        }
    }

@ashleyhindle
Copy link
Collaborator

Thanks for raising @inxilpro 💪 I like the 'runningInConsole' approach too, does that work on your side?

@pushpak1300
Copy link
Member

+1 for runningInConsole approach.

@inxilpro
Copy link
Contributor Author

Excluding it when running in console would mean that if you cached routes locally for some reason, that route wouldn’t be available…

@inxilpro
Copy link
Contributor Author

I also just tested and confirmed that checking routesAreCached is not enough to solve the problem, although that check probably should be added as well for performance reasons.

@inxilpro
Copy link
Contributor Author

Another approach would be to introduce a BrowserLogsController instead of using a closure. That would address this issue and arguably be slightly more performant with route caching, since we wouldn't be dealing with a serialized closure. (The performance benefit is negligible, but sometimes it's nice to eek out micro-optimizations when you're writing package code.)

@NickSdot
Copy link

I also just tested and confirmed that checking routesAreCached is not enough to solve the problem, although that check probably should be added as well for performance reasons.

I deleted that comment because it of course wouldn't solve the issue when running route:cache; I was a bit too fast with my comment. 🥶

@calebdw
Copy link
Contributor

calebdw commented Aug 13, 2025

Can we get this merged? Our CI is broken until this is fixed...

@ashleyhindle
Copy link
Collaborator

Let's merge the static fix, then I'll look at a better one - thanks for your insights on this @inxilpro 💪

@ashleyhindle ashleyhindle merged commit fb10a93 into laravel:main Aug 13, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot optimize app when boost is installed
6 participants