Change record status: 
Project: 
Introduced in branch: 
9.3.x
Introduced in version: 
9.3.0
Description: 

Symfony has added a new ::getMainRequest() method to RequestStack in Symfony 5.

In preparation for this, Drupal core has added a forward compatibility layer at \Drupal\Core\Http\RequestStack implementing the new method.

If you are replacing the request stack object in contrib or custom code, you should update to use the new \Drupal\Core\Http\RequestStack object to remain forwards compatible with Symfony 5 and 6.

For example, to also remain compatible with Drupal 9.2.x:

use Drupal\Core\Http\RequestStack as DrupalRequestStack
use Symfony\Component\HttpFoundation\RequestStack as SymfonyRequestStack

    if (class_exists(DrupalRequestStack::class)) {
      $request_stack = new DrupalRequestStack();
    }
    // Legacy request stack.
    else {
      $request_stack = new SymfonyRequestStack();
    }
Impacts: 
Module developers