Skip to content
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

View events not firing anymore since 9.36 #44650

Closed
stayallive opened this issue Oct 19, 2022 · 4 comments · Fixed by #44653
Closed

View events not firing anymore since 9.36 #44650

stayallive opened this issue Oct 19, 2022 · 4 comments · Fixed by #44653

Comments

@stayallive
Copy link
Contributor

stayallive commented Oct 19, 2022

  • Laravel Version: 9.36.2 (same for 9.36.0 & 9.36.1)
  • PHP Version: 8.1.10

Description:

Listening to composing events no longer seems to work, probably related to: #44487.

$this->app['events']->listen('composing:*', ...);            // barryvdh/laravel-debugbar
$this->app['events']->listen("composing: {$viewName}", ...); // laracasts/utilities

Unsure if this was ever intended to work but this seems like a very breaking change since this always used to work and people are seemingly relying on it. It looks like an unintentional BC slipped in the 9.36 release.

Steps To Reproduce:

The easiest is to install barryvdh/laravel-debugbar (barryvdh/laravel-debugbar#1354, barryvdh/laravel-debugbar#1355) for example which will no longer show any views being rendered. This also breaks laracasts/utilities and of course any userland code using events directly to listen for composing: or other view related events not registered using View::composer.

@bjhijmans
Copy link

I noticed the same thing. It only threw the event for the outermost view, but not for any views included from there.

@nunomaduro
Copy link
Member

On the PR #44487, I've consider that there is no need to fire view events if no "creators" and "composers" exist. Yet, seem that a few packages were relying on these events even without registering "creators" and "composers".

So, there is two solutions:

  • 1: Revert the micro-optimization that avoids 2 events being dispatched every time a view / component gets rendered.
  • 2: Pull request to those 2 lines for those packages:
$this->app['view']->creator('*', fn () => true);
$this->app['view']->composer('*', fn () => true);

@stayallive
Copy link
Contributor Author

These are the 2 cases identified, probable that many other packages do something similar and/or userland code also relies on this. Personally I feel like this should be changed in 10.x and basically deprecate the view events.

Seems more than fine to refactor code to use creator and composer directly but it seems a little on the BC break path... but I'll leave that call up to you how you consider this since you could also argue that it was never intended for anyone to use those events directly.

@nunomaduro
Copy link
Member

Prepared the PR, in case we decide to revert the code: #44653.

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 a pull request may close this issue.

3 participants