Closed (fixed)
Project:
Gutenberg
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
19 Jun 2020 at 21:40 UTC
Updated:
30 Jul 2021 at 13:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
cantrellnm commentedThis patch assumes
#cachedata in$block->build()should override cache data from functions like$block->getCacheTags().Comment #3
cantrellnm commentedComment #4
martin_andersn commentedHi!
I will attempt to replicate this bug first. Any more information you can provide me towards this goal would be greatly appreciated!
What Drupal version did you run it with?
What other modules, both active not active worth mentioning?
Composer used for install ?
can you check if this problem still persist after recent core updates and Gutenberg module updates?
I love that you provided at patch in the same breath as you reported the bug! First i need to replicate the issue and then test the patch if the above question indicates the problem stil exist.
Thank you for your continued interest and input on this project :)
Best, Martin Andersen
Comment #5
cantrellnm commentedThanks for looking into it, Martin.
I'm using Composer for install, and just replicated the error with Drupal 8.9.2 and Gutenberg 1.11 with the patch from issue 3137872 that was already committed but not released in the 1.x branch. Replicated also with Drupal 8.9.3 and Gutenberg 2.0-beta2 (no patch since the commit is included in that release).
It happens if you're adding a Drupal plugin-type block to a node through Gutenberg where the block's php class doesn't use a
#cachekey in the array returned by itsbuild()function. The block works on the node edit form, but then the page breaks after saving when trying to view the node. ThecacheabilityMetadata()function insrc/Plugin/Filter/BlockFilter.phpassumes that$build['#cache']is set, but it doesn't have to be. And then that null value in the$metadataarray gets used as a parameter forsetCacheTags()and throws this error.There are probably contrib modules where this could happen, but in my case it was a custom module defining a block plugin. Something as simple as the example block at https://www.drupal.org/docs/8/creating-custom-modules/creating-custom-blocks/create-a-custom-block would work to replicate to problem.
Comment #6
martin_andersn commentedhi cantrellnm.
Excellent! you provide very detailed instructions on the steps to reproduce, big +! :D
## 'src/Plugin/Filter/BlockFilter.php' - Gutenberg version: '8.x-2.0-beta2':
Are you still getting a null thrown if using Gutenberg version: '8.x-2.0-beta2' ?
Thinking out loud here, but if problem stil presist maybe something like:
array_replace_recursive (SOME_VALUE $metadata['tags'], $build['#cache']['tags'] ): SOME_VALUEWill investigate this.
Keep you posted.
.m
Comment #7
cantrellnm commentedYes the issue is also in 8.x-2.0-beta2. Using
array_replace_rescursive()sounds fine to me, but doesn't fix the problem that$build['#cache']['tags']may not be defined. A block doesn't need to use a'#cache'key in the array it returns from thebuild()function.Patch in #2 fixes that problem, and falls back to using the block's cache data from functions like
$block->getCacheTags()if needed. Or if we want cache data from both the$buildarray and block functions, something like this might work (assuming PHP 7):$metadata['tags'] = array_replace_recursive($metadata['tags'], $build->getCacheTags(), $build['#cache']['tags'] ?? []);Comment #8
nimoatwoodwayConfirm. Patch in #2 fixes this issue for 8.x-2.0-beta2.
Comment #9
thorandre commentedThis is relevant to https://www.drupal.org/project/gutenberg/issues/3213784
Marco is working on that and will evaluate the patch here also. We should see a solution for this by the end of next week.
Comment #10
szeidler commentedAny further development goes against 8.x-2.x
Comment #11
szeidler commentedSince Drupal 8.x-2.0 the problem seems to be solve, because of the major restructuring of the block processor. I think we can close this issue therefore. Feel free to create another issue, if you still experience the issue.
Marking it as fixed to grant credits for the patch + reviews.
Comment #13
szeidler commented