Closed atiline closed 2 years ago
Sounds alright. But may I wonder how did you experience that?
If my request contains some "hard" logic (many db queries, some http requests to another hosts etc) I use some trick - on Application::EVENT_AFTER_REQUEST I call another php process (passing args via cache or db) and run my logic there (in console application).
Sometimes I forget that on this application state I can't use registering assets and it's really hard to debug why JS files were not atached. Some warning will be useful.
Formarly sounds reasonable but applies limits to those rare justified cases I've seen around. So this would be either an error or an intention of a developer - in first case framework should not apply BC breaking limits, in second case framework should not attempt to solve developers mistake. It's edge case.
I wonder if registering anything after request could be a valid use-case...
@yiisoft/reviewers, @yiisoft/core-developers, @yiisoft/yii2 what do you think?
I agree with @lubosdz - even though it is a valid issue it's not common and should be resolved by the developer.
I think the wish of the OP is not to support this behaviour, but to throw some warning when this happens. Just throwing a notice should not be a BC?
Yes, warning could be added, indeed.
The merged PR seems to trigger errors using the app basic template, see https://github.com/yiisoft/yii2/pull/18972#issuecomment-950700577
To be investigated / fixed before next yii2 release.
Comment https://github.com/yiisoft/yii2/pull/18972#issuecomment-950723220 has the correct assumption. Pull request https://github.com/yiisoft/yii2/pull/18975 implements the suggestion from this comment
Hi!
I suggest throwing an exception or calling \Yii::warning or \Yii::error when functions yii\web\View::registerJs, yii\web\View::registerCss etc are called after function yii\web\View::endBody() was called.
Now there are any checks of Application or View states.
Some example - you can call registerJs() after Application::EVENT_AFTER_REQUEST. Any JS will be added to response.