Problem/Motivation

When a redirect rule matches (e.g., /old → /new), the request crashes with:
TypeError: Drupal\Core\Render\BubbleableMetadata::applyTo(): Argument #1 ($build) must be of type array, Drupal\Core\Routing\TrustedRedirectResponse given
This happens in src/EventSubscriber/RedirectSubscriber.php when cache metadata is applied to a TrustedRedirectResponse using BubbleableMetadata::applyTo(), which only accepts render arrays.

Steps to reproduce

Steps to reproduce
1.
Enable MyREST SEO redirect rules.
2.
Add rule: /old|/new|301|1.
3.
Visit /old.

Proposed resolution


Replace BubbleableMetadata::applyTo($response) with:
$response->addCacheableDependency($metadata);

Ensure the metadata sets:

max-age: 0 (no caching of redirect)

contexts: languages:language_interface, url.path (and url.query_args if the module supports preserving query)

tags: config:myrest_seo.redirects

Issue fork myrest_seo-3567629

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

sergeydruua created an issue. See original summary.

  • sergeydruua committed 0c59ede7 on 1.0.x
    Issue #3567629: Fix redirect TypeError; disable subscriber when Redirect...
sergeydruua’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

sergeydruua’s picture

Status: Fixed » Closed (fixed)