spatie / laravel-ray

Debug with Ray to fix problems faster in Laravel apps
https://myray.app
MIT License
291 stars 62 forks source link

Infinite loop caused by `report` function call inside of a view #360

Open ganyicz opened 4 months ago

ganyicz commented 4 months ago

When both Ray and Flare are installed on a Laravel project and a report function is called inside of a view, the Laravel app ends up in an infinite loop when Ray tries to create a Flare report:

https://github.com/spatie/laravel-ray/blob/1d10366c91e38fd0e1284988f66551dea0e03e54/src/Watchers/ExceptionWatcher.php#L63-L68

While creating a Flare report, an array representation of the stack trace is produced by the spatie/backtrace package, where each method call argument is ran through these "reducer" classes. This issue is specifically caused by the StringableArgumentReducer which invokes the magic __toString() method on any argument in the stack trace that implements it. In Laravel, this method is implemented by the View class and a view is normally passed as an argument to the Response::setContent() function. Casting the view into a string causes it to re-render, calling the report function again, repeating this whole process.

While writing this issue I realized this might have more implications in the Flare client package. I will create a separate issue with an example repo there, linking back to this.