0

I'm building a drupal 9 commerce 2 site, one problem that I have is that the variation switch that works with ajax is having problems on the production server.

I have analyzed the network tab of DevTools, the situation is the following:

  • I go to a product and can switch between its variations.
  • If I add a product to the cart, then I cannot switch to another variation, the ajax request is made but instead of returning a JSON the response is a html with the whole page which results in the error.

The Ajax request url is something like:

/product/54?v=3037&ajax_form=1&_wrapper_format=drupal_ajax

I has able to get this error

The website encountered an unexpected error. Please try again later.
Drupal\Core\Form\Exception\BrokenPostRequestException: in Drupal\Core\Form\FormBuilder->buildForm() (line 329 of core/lib/Drupal/Core/Form/FormBuilder.php).
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 97)
Drupal\commerce_product\ProductLazyBuilders->addToCartForm('1', 'full', 1, 'de')
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #lazy_builder callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 788)
Drupal\Core\Render\Renderer->doCallback('#lazy_builder', Array, Array) (Line: 353)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 160)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 161)
Drupal\Core\Render\Renderer->renderPlain(Array) (Line: 175)
Drupal\Core\Render\Renderer->renderPlaceholder('callback=commerce_product.lazy_builders%3AaddToCartForm&args%5B0%5D=1&args%5B1%5D=full&args%5B2%5D=1&args%5B3%5D=de&token=sVcpy-DvoH5bvQI2TOha5NnBCi52xXNtoJZ_ckfvfWs', Array) (Line: 693)
Drupal\big_pipe\Render\BigPipe->renderPlaceholder('callback=commerce_product.lazy_builders%3AaddToCartForm&args%5B0%5D=1&args%5B1%5D=full&args%5B2%5D=1&args%5B3%5D=de&token=sVcpy-DvoH5bvQI2TOha5NnBCi52xXNtoJZ_ckfvfWs', Array) (Line: 547)
Drupal\big_pipe\Render\BigPipe->sendPlaceholders(Array, Array, Object) (Line: 305)
Drupal\big_pipe\Render\BigPipe->sendContent(Object) (Line: 112)
Drupal\big_pipe\Render\BigPipeResponse->sendContent() (Line: 381)
Symfony\Component\HttpFoundation\Response->send() (Line: 20)

If I disable the cache for dynamic_page_cache in settings.php everything works:

$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

Is there a better solution for that?

felipep
  • 2,442
  • 1
  • 28
  • 35
  • Might help get an answer if you add the html that is returned. Did you check the error log? – 2pha Apr 25 '23 at 22:52

0 Answers0