cms icon indicating copy to clipboard operation
cms copied to clipboard

[5.x] Prevent infinite loops with Laravel Telescope

Open duncanmcclean opened this issue 10 months ago • 5 comments

This pull request fixes an issue with Laravel Telescope installed, where an infinite loop would occur if you had entries which link to each other.

Right now, when Telescope encounters an Entry object (whether that be in an event, or in an authorization gate), it'll attempt to serialize it using ->jsonSerialize() which'll return an evaluated array of the augmented entry.

However, if you have an entry which relates back to itself, this evaluated array can cause an infinite loop.

This PR addresses that by returning a shallow augmented array instead, which prevents relationships from being evaluated in the same way, therefore preventing the infinite loop issue.

This fix relies on the formatForTelescope method, added in these Telescope PRs:

  • https://github.com/laravel/telescope/pull/1562
  • https://github.com/laravel/telescope/pull/1566

Fixes #10782.

duncanmcclean avatar Jan 24 '25 17:01 duncanmcclean

Good catch! Looks like I missed adding the hook into Telescope's RequestWatcher (which serializes view data) 🙈

I've opened a PR on the Telescope side to address this: https://github.com/laravel/telescope/pull/1566

duncanmcclean avatar Feb 06 '25 13:02 duncanmcclean

Telescope v5.5.0 was just tagged with my 2nd PR. After updating Telescope, you should no longer see an infinite loop on the entry show page.

duncanmcclean avatar Feb 11 '25 17:02 duncanmcclean

Sorry, but it still happens 🙈

jasonvarga avatar Feb 17 '25 20:02 jasonvarga

This definitely still gives me an infinite loop. Are you sure you're using a link field? It seems ok with entries fields.

I'm on Telescope 5.6.0, and tried Laravel 11 and 12.

jasonvarga avatar Mar 27 '25 14:03 jasonvarga

Going to mark this as a draft for the time being, until I have time to loop back to this.

duncanmcclean avatar Apr 03 '25 10:04 duncanmcclean