chapter-three / next-drupal

Next.js for Drupal has everything you need to build a next-generation front-end for your Drupal site: SSG, SSR, and ISR, Multi-site, Authentication, Webforms, Search API, I18n and Preview mode (works with JSON:API and GraphQL).
https://next-drupal.org
MIT License
625 stars 172 forks source link

LogicException: leaked metadata was detected #421

Open jean-louis opened 1 year ago

jean-louis commented 1 year ago

Hi all, sorry for my bad english.

I use drupal as Identity for a frontend in next.js with the "Authorization Code Grant". After upgrading core and various contrib modules i have the following exception at login:

LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\Core\Routing\TrustedRedirectResponse. in Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (line 154 of core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php).

Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 68)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 713)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

there are many issues on drupal.org that talk about it and the most interesting is the following #2638686: Exception in EarlyRenderingControllerWrapperSubscriber is a DX nightmare, remove it

these are versions of a selection of installed modules:

After some "debugging" I noticed that the problem doesn't arise using version 1.4.0 of the next module, but looking at the changes made from version 1.4.0 to 1.6.2 I can't figure out what could cause this problem.

The only way I found to make the login process work with the versions listed above, was to apply the patch (attached to 3334339) to the simple_oauth Oauth2AuthorizeController::redirectToCallback method, but I'm wondering if these changes can lead to other types of problems.

Any suggestions on the possible cause or on the created patch are welcome, thank you

P.S. Do you have this error?

shadcn commented 1 year ago

I'll take a look at this. This only happens when using the Authorization Code Grant?

iamfredrik commented 1 year ago

Any update on this issue? I get this error when visiting my Next.js site after enabling the Rules module in Drupal. I'm using Next-Drupal 1.6.0.

Location:http://my.lndo.site/en/jsonapi/menu_items/main

LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\jsonapi\CacheableResourceResponse. in Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (line 154 of /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php).

Edit: I see that the fix from https://github.com/chapter-three/next-drupal/pull/473 has already been applied to the module I'm using, so it's caused by some other related issue. Any ideas?