Problem/Motivation

On Drupal 11, when using ui_styles alongside with redirect module. stylesheet.css enter an infinite 301 redirect.

This is due to Drupal\redirect\EventSubscriber\RouteNormalizerRequestSubscriber.

Steps to reproduce

  • Enable redirect, ui_styles, ui_patterns modules and ui_suite_bootstrap theme
  • Create a content type with layout builder override
  • Create a node and try to add accordion

Proposed resolution

As redirect is widely used, ui_styles could be compatible directly by preventing redirect to process the ui_styles.stylesheet route.
Just by adding _disable_route_normalizer: true to route defaults.

Issue fork ui_styles-3503776

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mattlc created an issue. See original summary.

mattlc’s picture

Assigned: mattlc » Unassigned
Status: Active » Needs review

To be tested

grimreaper’s picture

Status: Needs review » Postponed (maintainer needs more info)

Hi,

Thanks a lot for the report.

But I can't reproduce, is it because my test environment is on D10?

In the Redirect event subscriber what are the variables values that it triggers a redirect?

goz’s picture

I confirm the issue with D11, and i'm using :
ui_patterns : 2.0.0-rc2
ui_styles: 8.x-1.15

After applying patch, i can add section to my layout.

goz’s picture

My bad, i reproduce in D10.4 and D10.3.

In ui_style.routing.yml file, route is defined with .css extension

ui_styles.stylesheet:
  path: '/ui_styles/stylesheet.css'
  defaults:
    _controller: 'Drupal\ui_styles\Controller\StylesheetController::generateStylesheet'
    _title: 'UI Styles CSS generator'
  requirements:
    _permission: 'access content'

In Nginx, the following configuration add ?q= because of .css extension.


    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|eot|ttf|woff|woff2)$ {
        try_files $uri @rewrite;
    }

So in web/modules/contrib/redirect/src/EventSubscriber/RouteNormalizerRequestSubscriber.php, at the end of onKernelRequestRedirect method, redirect_uri is

/ui_styles/stylesheet.css?q=/ui_styles/stylesheet.css&prefix....

so redirect module redirect to this url.

?q should not be there, but it's caused by nginx configuration and because it's not a real CSS file but generated on the fly by controller.

Renaming controller path to something without .css extension solve the issue

goz’s picture

Status: Postponed (maintainer needs more info) » Needs work
grimreaper’s picture

Assigned: Unassigned » grimreaper
grimreaper’s picture

Assigned: grimreaper » pdureau

MR rebased and updated.

@pierre, can you test with Drush webserver please?

grimreaper’s picture

Version: 8.x-1.15 » 8.x-1.x-dev
Status: Needs work » Needs review
pdureau’s picture

Assigned: pdureau » grimreaper
Status: Needs review » Reviewed & tested by the community

it works with "drush rs"

~/Projects/Drupal/ui_patterns_2/ $ vendor/bin/drush st
Drupal version   : 11.1.2                                                                  
Site URI         : http://default                                                          
DB driver        : sqlite                                                                  
DB port          :                                                                         
DB username      :                                                                         
DB name          : db.sqlite                                                               
Database         : Connected                                                               
Drupal bootstrap : Successful                                                              
Default theme    : ui_suite_bootstrap                                                      
Admin theme      : claro                                                                   
PHP binary       : /usr/bin/php                                                            
PHP config       : /etc/php.ini                                                            
PHP OS           : Linux                                                                   
PHP version      : 8.3.16                                                                  
Drush script     : /home/pierre/Projects/Drupal/ui_patterns_2/vendor/bin/drush.php         
Drush version    : 13.3.3.0                                                                
Drush temp       : /tmp                                                                    
Drush configs    : /home/pierre/Projects/Drupal/ui_patterns_2/vendor/drush/drush/drush.yml 
Install profile  : standard                                                                
Drupal root      : /home/pierre/Projects/Drupal/ui_patterns_2/web                          
Site path        : sites/default                                                           
Files, Public    : sites/default/files                                                     
Files, Temp      : /tmp   

i have http://127.0.0.1:8888/ui_styles/stylesheet?prefix=.ck-content&srblbb without the .css extension:


HTTP/1.1 200 OK
Host: 127.0.0.1:8888
Connection: close
X-Powered-By: PHP/8.3.16
Content-Type: text/css; charset=UTF-8
Cache-Control: must-revalidate, no-cache, private
Date: Fri, 07 Feb 2025 15:50:12 GMT
X-Drupal-Dynamic-Cache: MISS
Content-language: en
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Drupal-Cache-Tags: http_response
X-Drupal-Cache-Contexts: url.query_args:prefix user.permissions
X-Drupal-Cache-Max-Age: 31536000
Expires: Sun, 19 Nov 1978 05:00:00 GMT
X-Generator: Drupal 11 (https://www.drupal.org)
Content-Length: 45259
X-Drupal-Cache: MISS

  • grimreaper committed 0343b00c on 8.x-1.x authored by mattlc
    Issue #3503776 by mattlc, grimreaper, goz, pdureau: Avoid redirect...
grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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