Problem/Motivation
Install minimal, click add content, click add content type, fill in title, save, click add content, you get You have not created any content types yet
You can watch on https://youtu.be/cAPHj9sEkz0?t=1m2s (the first minute is just installing)
Adding more node types does not help. drush cr does help and node/add begins to work.
Proposed resolution
<-- This was fixed in #2579887: EntityListBuilder requires cache tags
* Add the list tag: \Drupal\Core\Entity\EntityType::getListCacheTags
in \Drupal\Core\Entity\EntityListBuilder::render
Add the list tag + access cache contexts to \Drupal\node\Controller\NodeController::addPage
Remaining tasks
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Add automated tests | Instructions | See #21 done in #24 | |
Draft a change record for the API changes | Instructions | NOT NEEDED (#23) |
User interface changes
No
API changes
No
Data model changes
No
Comment | File | Size | Author |
---|---|---|---|
#34 | 2579847-26.patch | 2.7 KB | YesCT |
#34 | 2579847-26-tests-only.patch | 1.23 KB | YesCT |
#26 | 2579847-26.patch | 2.7 KB | hussainweb |
#22 | interdiff.txt | 1.01 KB | marcvangend |
#22 | 2579847-22.patch | 2.59 KB | marcvangend |
Comments
Comment #2
chx CreditAttribution: chx commentedComment #3
chx CreditAttribution: chx commentedComment #4
marcvangendCan this be related to #550254: Menu links are sometimes not properly re-parented? If I remember correctly (https://www.drupal.org/node/550254#comment-3851154) there was a link between that issue and the "You have not created any content types yet" message.
Comment #5
chx CreditAttribution: chx commentedComment #6
dawehnerWorking on a test
Comment #7
chx CreditAttribution: chx commentedComment #8
dawehnerThe fix is probably all about adding the right cache tags.
Comment #9
dawehnerRemoved the GIF, because I don't want mobile users to download 2MB.
Comment #10
dawehnerThe fix would be to change
\Drupal\Core\Entity\EntityListBuilder::render
to also include the entity list tag.Comment #11
swentel CreditAttribution: swentel commentedConfirmed, some cache/menu routing is not cleared/refreshed at the right moment I presume
Same happens when deleting a content type, you'll still see the content type when clicking 'Add content' (note, best to add 2 first, clear cache, then delete), so we should probably write a test for that as well.
Comment #12
dawehnerAdded the task as novice task.
Comment #13
dawehnerOh well, actually this is the wrong fix, but probably also a cause for potential many critical bugs
Comment #14
marcvangendOK, I'll try to make a patch.
Comment #17
marcvangendThis adds the cache tags.
@dawehner I'm not sure what you mean by "access cache contexts". I'm still learning about cache context and tags.
Comment #18
Wim LeersI've explained this to @marcvangend in IRC :)
Comment #19
marcvangendNew patch, adds the cachability metadata from the node type access object.
BTW the patch in #17 already came back green, so that would mean test coverage isn't 100% yet.
Comment #20
Wim Leers@YesCT asked me to post #18 here.
Comment #21
Wim LeersWe usually call this
$build
.Perfect :)
Indeed, we are missing some
assertCacheTag()
andassertCacheContext()
assertions.Comment #22
marcvangendOK, $build it is.
Comment #23
YesCT CreditAttribution: YesCT commentedconfirmed with @Wim Leers that no change record is needed (and filled out more in the issue summary)
Comment #24
marcvangendThis should test the presence of cache tags and context.
Comment #25
hussainwebReally small nitpick. :)
Also, I was wondering if this happened with Standard profile and it doesn't. The difference is the field_ui module. If I enable field_ui module, this issue doesn't exist anymore. I am not sure what exactly
field_ui
does but dynamic_page_cache can't find thenode/add
in cache anymore. Withoutfield_ui
, it always returns a cached version.Comment #26
hussainwebCross-post. Here is the combined patch from #24 and #25.
Comment #27
marcvangendThanks Hussain, that comma may be small, but very annoying when forgotten.
Comment #28
Wim LeersThe root cause is missing cacheability metadata. This issue fixes that.
The reason this is only a problem with the Minimal install profile is that in that install profile, the
/node/add
route (node.add_page
) is NOT marked as an admin route (_admin_route: TRUE
), but in the Standard install profile it is.Dynamic Page Cache does not cache responses for admin routes. Hence in Standard profile, there is no problem (
/node/add
is an admin route), but in the Minimal profile there is a problem (/node/add
is not an admin route).Comment #29
Wim LeersAnd finally, the reason Standard marks it as an admin route and Minimal does not: this line in
standard.install
:Plus this in
NodeAdminRouteSubscriber
:Correcting the title to reflect the actual cause.
Comment #30
hussainweb@Wim Leers: I agree that the root cause for this issue is fixed; however, I am still confused and concerned that there might be something about the field_ui module we are not taking into account here. I had tested earlier and to make sure, I tested again.
In short, either field_ui does something to fix this OR the presence of at least one other content type fixes the caching. I can't verify if that is the case because once field_ui is enabled, I can't disable it.
Comment #31
YesCT CreditAttribution: YesCT commentedfyi, did a git bisect
5e8523ecb95f1530e80ea2d9929135ef9b3f8733 is the first bad commit
#2429617: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!)
Comment #32
Wim LeersYep, that makes sense, Dynamic Page Cache exposed a long pre-existing problem: missing cacheability metadata on that route.
Comment #33
dawehnerIn other words we should require #cache on every controller which returns a render array, to ensure what is going on.
@hussainweb
The reason why field_ui helps here is that field_ui rebuilds the router in
field_ui_entity_bundle_create()
which causes the 'route_match' cache tag to be invalidated, see
\Drupal\Core\EventSubscriber\CacheRouterRebuildSubscriber::onRouterFinished
This cache tag is part of every page, given that almost always something requires it.
Comment #34
YesCT CreditAttribution: YesCT commented@marcvangend thanks for the tests in #24
it is common to make a tests only patch, and a patch with the tests and the fix. and let the testbot run on both. That way, the reviews (and committers) can see the test is failing and in the correct way.
Comment #35
YesCT CreditAttribution: YesCT commentedtinying up the issue summary
Comment #36
dawehner@Wim Leers
Well to be fair otherwise this bug would have not been exposed given how often anonymous users have access to
/node/add
#2579887: EntityListBuilder requires cache tags is another issue like that
Comment #37
hussainweb@dawehner: Thanks for the explanation. That makes sense.
Comment #40
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedNot blocking any of this, RTBC + 1 to the patch. Just some thoughts:
What I don't like about all of this is:
- Why do we conditionally make something an admin route?
I don't think node/add should ever be admin. I think the decision to use admin_theme should be a new property admin_theme as usually admin route denotes something else - I think. Though I might be wrong; Do we have a definition of what admin_route means on a route?
Comment #41
MustangGB CreditAttribution: MustangGB commentedThis was my concern also, I use the minimal profile because I don't want to spend time trawling through all the modules that I don't need for my project and deleting the content type bloat, I wouldn't expect any conditional stuff like this, especially not potentially security related stuff that could bite me at a later date.
Comment #42
Wim Leers#40 + #41: That's a completely separate problem, and a design decision that was made many years ago. Can you please discuss that in a separate issue, so that this one doesn't get derailed? Thanks.
Comment #43
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedI think the patch is good, however it likely would have been simpler to just add max-age=0 or no_cache: TRUE for the critical bug fix of this, then make it cacheable later.
Comment #44
alexpottCommitted db0ece0 and pushed to 8.0.x. Thanks!
Comment #46
marcvangendComment #47
Wim Leers