-
Notifications
You must be signed in to change notification settings - Fork 642
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
[3.2]: Live Preview does not show changes #4542
Comments
Okay, we've found the issue in our module code, we have a listener for |
Sounds like that code needs to be revisited then. In case it helps, here’s how previewing entries works in Craft 3.2:
|
Thank you for your detailed response. Of course we did update our code after we've found the cause of our problems. I can understand that the releae of a new major version is a stressful situation for you and that the problem described here is not a major issue. However I would like to point out that:
I thought of creating a pull request to at least implement a cache clear method on the UrlManager which could solve the second issue. However, as this would be only a partial solution, I think it would be more sensible to look for a more wholesome solution. |
Can you post your code for this? |
Sure, here is the actual code that triggered the error. Basically to reproduce the issue all you need is some custom module which does the following: namespace acme;
use Craft;
use craft\web\Application;
use yii\base\ActionEvent;
use yii\base\Event;
class Module extends \yii\base\Module {
public function init() {
parent::init();
Event::on(
Application::class, Application::EVENT_BEFORE_ACTION,
[$this, 'onBeforeAction']
);
}
public function onBeforeAction(ActionEvent $event) {
$element = Craft::$app->getUrlManager()->getMatchedElement();
}
} Calling We meanwhile found similiar code in other projects where we use it for caching and preprocessing stuff. |
Just fixed this for the next release. Going forward, preview requests will reset the matched element on UrlManager before re-routing the request. To get the fix early, change your "require": {
"craftcms/cms": "dev-develop#e2457ceece352edee53916008103bf866ed6ab3b as 3.2.2",
"...": "..."
} Then run |
Awesome! Please excuse my tenacity and thank you for looking into it. |
Description
Starting with Craft 3.2 the live preview does not update in our projects after the editor changes something in the element form.
Steps to reproduce
Additional info
Investigation
I've traced the actions using xDebug to check whether this is a bug in my code. This is what I've could reconstruct:
Application::handleRequest
Request::resolve
UrlManager::parseRequest
UrlManager::_getRequestRoute
UrlManager::_getMatchedElementRoute
UrlManager::_getMatchedElementRoute
seems to be the problem here as the url manager has cached the result of the initial url matching (usingUrlManager::_matchedElementRoute
) and this cached route contains the original, currently published version of the element. As the method does not run and opts out early, the placeholder element set by the preview controller is not being picked up here.So, as far as I can see through this, I think that the preview controller should clear the cached route of the UrlManager before handing of the request to the normal request chain so it gets reevaluated.
Sidenote: I initially observed that the element returned by
UrlManager::getMatchedElement
is wrong in preview requests, it also points to the currently published element. As this call is cached too (usingUrlManager::_matchedElement
) it might be a good idea to clear that cache too?The text was updated successfully, but these errors were encountered: