Skip to content

Commit 5d1ac80

Browse files
authored
[BUGFIX] Disable frontend cache in edit mode (#90)
Disable the frontend cache whenever the `editMode` query parameter is present. This keeps visual editor requests from using cached page output without excluding the parameter from cHash handling globally.
1 parent 2e705fa commit 5d1ac80

4 files changed

Lines changed: 39 additions & 6 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TYPO3\CMS\VisualEditor\Middleware;
6+
7+
use Psr\Http\Message\ResponseInterface;
8+
use Psr\Http\Message\ServerRequestInterface;
9+
use Psr\Http\Server\MiddlewareInterface;
10+
use Psr\Http\Server\RequestHandlerInterface;
11+
use TYPO3\CMS\Frontend\Cache\CacheInstruction;
12+
13+
readonly class DisableCacheInEditModeMiddleware implements MiddlewareInterface
14+
{
15+
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
16+
{
17+
$params = $request->getQueryParams();
18+
if (isset($params['editMode'])) {
19+
$cacheInstruction = $request->getAttribute('frontend.cache.instruction', new CacheInstruction());
20+
$cacheInstruction->disableCache('EXT:visual_editor: The editMode parameter forced the cache to be disabled.');
21+
$request = $request->withAttribute('frontend.cache.instruction', $cacheInstruction);
22+
}
23+
24+
return $handler->handle($request);
25+
}
26+
}

Configuration/RequestMiddlewares.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use TYPO3\CMS\VisualEditor\Middleware\DisableCacheInEditModeMiddleware;
56
use TYPO3\CMS\VisualEditor\Middleware\PersistenceMiddleware;
67

78
return [
@@ -15,5 +16,15 @@
1516
'typo3/cms-adminpanel/sql-logging',
1617
],
1718
],
19+
'typo3/cms-visual-editor/disable-cache-in-edit-mode-middleware' => [
20+
'target' => DisableCacheInEditModeMiddleware::class,
21+
'before' => [
22+
'typo3/cms-frontend/page-argument-validator',
23+
'typo3/cms-frontend/prepare-tsfe-rendering',
24+
'typo3/cms-frontend/tsfe', // TODO typo3/cms-frontend/tsfe can be dropped if TYPO3 14 is lowest supported version
25+
'typo3/cms-frontend/page-resolver',
26+
'typo3/cms-adminpanel/sql-logging',
27+
],
28+
],
1829
],
1930
];

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"pluswerk/grumphp-config": "^10.2.7",
3232
"saschaegerer/phpstan-typo3": "^2.1.1 || ^3.0.1",
3333
"ssch/typo3-rector": "^3.14.1",
34-
"typo3/cms-install": "^13.4.28 || ^14.3.0",
35-
"typo3/cms-workspaces": "^13.4.28 || ^14.3.0",
34+
"typo3/cms-install": "^13.4.28 || ^14.3.2",
35+
"typo3/cms-workspaces": "^13.4.28 || ^14.3.2",
3636
"typo3/testing-framework": "^9.5.0",
3737
"typo3fluid/fluid": "^4.6.1 || ^5.3.1"
3838
},

ext_localconf.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,3 @@
1515
if (!class_exists(ModifyRenderedContentAreaEvent::class)) {
1616
class_alias(V13_RenderContentAreaEvent::class, ModifyRenderedContentAreaEvent::class);
1717
}
18-
19-
// exclude editMode from chash: If the parameter is present, the middleware already stops the normal rendering.
20-
$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters'] ??= [];
21-
$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters'][] = 'editMode';

0 commit comments

Comments
 (0)