我正在构建一个 drupal 9 commerce 2 站点,我遇到的一个问题是与 ajax 一起使用的变体开关在生产服务器上出现问题。
我分析过DevTools的network选项卡,情况如下:
Ajax 请求 url 是这样的:
/product/54?v=3037&ajax_form=1&_wrapper_format=drupal_ajax
我能够得到这个错误
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)
如果我在 settings.php 中禁用 dynamic_page_cache 的缓存,一切正常:
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
有更好的解决方案吗?