Problem/Motivation

CSS aggregation isn't automatically disabled in ^10.1 in maintenance mode and doesn't aggregate CSS for users without the 'access site in maintenance mode' permission, resulting in unstyled pages.

Steps to reproduce

  1. Install Drupal core ^10.1
  2. Make sure no aggregated CSS for the maintenance page is saved to disk. Delete the aggregated asset directory if necessary.
  3. Enable CSS aggregation and turn on maintenance mode.
  4. Visit the site with a user that does not have the 'access site in maintenance mode' permission. You should end up with an unstyled page.
  5. Check the browser console; in both Firefox and Chrome, you should see some variation of an error that the aggregated CSS was not loaded due to corrupt or incorrect content type, as it's actually serving the maintenance page HTML rather than CSS.

Proposed resolution

At Neurocracy/Omnipedia we settled on adding '_maintenance_access': true option to the 'system.css_asset' route as a workaround to allow us to use aggregated CSS, but a better solution may be to disable CSS aggregation automatically like JS aggregation seems to be in maintenance mode.

Remaining tasks

TBD.

User interface changes

CSS actually loads.

API changes

None?

Data model changes

None?

Release notes snippet

TBD.

Comments

Ambient.Impact created an issue. See original summary.

cilefen’s picture

Component: system.module » asset library system
lauriii’s picture

Priority: Normal » Major
catch’s picture

StatusFileSize
new2.98 KB

Patch is somewhat self-explanatory, there already exists code that tries to do this, at least since 2015, but it's not checking the right thing consistently.

So an old bug but exposed by the new routes/controllers.

catch’s picture

StatusFileSize
new2.99 KB

Even the simplest patches need linting.

keshavv’s picture

Before the #5 patch.
Before applying the patch
After the #5 patch.
After applying the patch
Confirmed that the #5 patch working well.

keshavv’s picture

Status: Needs review » Reviewed & tested by the community
longwave’s picture

Is it possible to add test coverage for this? If it is by design that CSS/JS is not aggregated in maintenance mode we should probably have an assertion for this.

catch’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.99 KB
new4.97 KB

Yes we've already got test coverage that's similarly incomplete to the code so can extend that.

longwave’s picture

+++ b/core/modules/system/tests/src/Functional/System/SiteMaintenanceTest.php
@@ -89,6 +93,7 @@ public function testSiteMaintenance() {
     // JS should not be aggregated, so drupal.js is expected in the page source.

This comment should probably mention both CSS and JS.

The last submitted patch, 9: 3373328-test-only.patch, failed testing. View results

catch’s picture

StatusFileSize
new1.68 KB
new5.38 KB

Reworded a bit.

lauriii’s picture

+++ b/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php
@@ -133,10 +133,11 @@ public function processAttachments(AttachmentsInterface $response) {
+    $maintenance_mode = defined('MAINTENANCE_MODE') || \Drupal::state()->get('system.maintenance_mode');

+++ b/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php
@@ -311,17 +311,19 @@ protected function renderPlaceholders(HtmlResponse $response) {
+    $maintenance_mode = defined('MAINTENANCE_MODE') || \Drupal::state()->get('system.maintenance_mode');

Have we stopped relying on the MAINTENANCE_MODE constant for the maintenance mode? I couldn't find where we're setting that for the actual maintenance mode.

I'm also wondering if you had a specific reason for not using dependency injection for the state?

ambient.impact’s picture

Glad to be the proverbial canary in the coal mine for this. Love seeing all the work going into this.

catch’s picture

Have we stopped relying on the MAINTENANCE_MODE constant for the maintenance mode?

It's still set in install.php. It used to be used in update.php, but that's been a route for several years now, we should open a new issue to factor it away entirely if there isn't already one - could add a special installer state service for pre-database that always returns it as true or something like that.

I'm also wondering if you had a specific reason for not using dependency injection for the state?

No I was just copying and pasting from HtmlAttachementsResponseProcessor which already doesn't use dependency injection for state for the js case. Can look at injecting it, as long as the patch is still patch release-safe we might as well do it here.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

For me, injecting state can be done in a followup given that using \Drupal was an existing pattern here, and I agree that the MAINTENANCE_MODE vs state variable is confusing and that we should open a followup to try and unify that if we can.

edit: #3058881: Update MaintenanceMode service and deprecate legacy API and #2538292: Remove atavistic references to MAINTENANCE_MODE == 'update' and supporting code and a number of similar issues already exist

  • lauriii committed b63275fe on 11.x
    Issue #3373328 by catch, keshav.k, Ambient.Impact, longwave: ^10.1 CSS...

  • lauriii committed d2392d13 on 10.1.x
    Issue #3373328 by catch, keshav.k, Ambient.Impact, longwave: ^10.1 CSS...
lauriii’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed b63275f and pushed to 11.x. Thanks! Also cherry-picked to 10.1.x.

catch’s picture

Was going to open a follow-up for dependency injection, but seeing #3058881: Update MaintenanceMode service and deprecate legacy API I wonder if it should just be that issue (or child issues of that issue for conversions).

ambient.impact’s picture

Awesome work. Thanks everyone.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

cilefen’s picture