Closed (fixed)
Project:
Drupal core
Version:
main
Component:
extension system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
19 Dec 2025 at 12:01 UTC
Updated:
20 Jul 2026 at 21:10 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #5
quietone commentedHi, in Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. Thanks.
I am restoring standard issue template so we can track progress on this issue.
@dotoree, There are instructions for rebasing a merge request. on drupal.org.
Comment #8
berdirDo you have a backtrace for this error to see where it originates?
11.3 supports OOP hooks for themes, so that could be related, but that's only attributes, not annotations?
Instead of this, it should probably be higher up and respect the scan setting
Comment #9
dotoree commented@berdir here is the backtrace:
and some errors:
Comment #10
berdirOk, so it is confirmed to be Drupal\Core\Hook\ThemeHookCollectorPass.
That's where we should look into this. \Drupal\Core\Hook\ThemeHookCollectorPass::filterIterator and the ModuleHookCollectorPass() should respect the file scan setting. Probably doesn't hurt to add your extra check too, but I think that alone won't fix the possibly considerably performance issue here.
Using the Assigned field to ping @nicxvan.
Comment #11
nicxvan commentedYeah we should add node module's to the disallow list.
https://git.drupalcode.org/project/drupal/-/blob/main/core/lib/Drupal/Co...
https://git.drupalcode.org/project/drupal/-/blob/main/core/lib/Drupal/Co...
Those are the two places we need to update.
Comment #12
nicxvan commentedComment #15
nicxvan commentedI'm going to clean up the mr since it's against 11.3 and doesn't follow the approach we should take.
Comment #19
richard.thomas commentedAfter updating to 11.3, we noticed significant performance degradation when clearing caches on a development site with a very large node_modules folder inside our site theme.
It looks to be due to the theme hook scanning going through the entire folder structure.
I've pushed up a simple MR https://git.drupalcode.org/project/drupal/-/merge_requests/15629 to make both HookCollectorPass and ThemeHookCollectorPass respect the file_scan_ignore_directories setting by merging that into the default list of excluded directories they had.
Doesn't seem to cause any issues with the existing tests and my local testing shows a big speedup (~30sec down to ~4sec for a cache rebuild with a populated node_modules directory that is configured to be ignored).
I'll see if I can add a specific test for the ignore directories option.
Comment #20
richard.thomas commentedI've added a couple of tests to https://git.drupalcode.org/project/drupal/-/merge_requests/15629 to check that directories configured in settings are ignored for both theme and module hook collection.
Comment #21
berdirThis looks good I think, not sure extensive the tests should be, we're about to deprecate .theme files on main, which would require at least a small change either here.
Maybe we can just add a SkipDeprecations attribute and a todo to remove in D13 to the tests and test modules as I *think* we can remove this when we remove BC as we know all extension directories already so we will _only_ need to look at their src/Hooks folder then, which should significantly simplify this in D13 as we can directly and only process that directory.
Comment #23
nicxvan commentedYeah, I am tempted to just hardcode node_modules and bower_components.
The ignore file setting is for a different purpose and I'm not sure we should conflate this.
I'm not super convinced as I write this, so I think it's worth discussing.
Comment #24
richard.thomas commentedI'd definitely prefer to give developers the option to configure additional exclusions (or remove the defaults). We could add an additional setting I guess, but I feel like the existing file_scan_ignore_directories would cover the same use-case.
The description in default.settings.php is:
It does mention extensions, but I think it's serving much the same purpose as what we need here (marking directories that won't have any Drupal code in them so don't bother recursively scanning them).
Comment #25
nicxvan commentedI think you're right, but let's also take a moment to update the comment there too then.
Comment #26
richard.thomas commentedI've had a go at updating the comment in the default.settings.php file to better reflect what the setting is doing.
I've also marked the new tests with #[IgnoreDeprecations] for when procedural hooks are deprecated and added a TODO comment to the new test theme/module files to remove them when procedural hooks are removed.
Comment #27
nicxvan commentedI have a few more comments on the MR, this is getting close! Thanks for working on this!
Here is the gist of the changes requested:
The comment should preserve the bit about the file api since that is still accurate
We only need to test the ignore directory bit since we already have tests for collection hooks, so we can drop the included_directory directories
Don't worry about the deprecation ignore, we'll add that when necessary if that issue gets in first, and we would do it by adding the attribute, if this gets in first I'll update the other issue.
Comment #28
nicxvan commentedI pushed up changes for my own feedback since I think we need to address this sooner rather than later, but I can't review this now since I've now contributed a bit directly.
Comment #29
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #30
nicxvan commentedI am rebasing this.
Comment #31
nicxvan commentedThis is ready for review again, good ideas.
I'll keep an eye on tests, but both pass locally so we should be good.
Comment #32
nicxvan commentedComment #33
berdirI think this is basically ready, there's one open MR on naming which I think could be improved but it's kind of unrelated (the confusing bit is already in HEAD).
How much this exactly benefits depends heavily on how large the node_modules folder is and how fast file IO is. I didn't build an isolated test script, where the difference would likely be more noticeable, with 2 themes with 1000 node modules/1700 directories, it was barely noticeable for a full drush cr with hyperfine:
11.4:
with the patch:
average is very close, variance is quite a bit lower, but that could also be anything else going on. Still, doesn't hurt.
Comment #34
godotislateSome minor comments. OK to self-RTBC.
Comment #35
berdirAccepted the suggestions.
Comment #39
godotislateCommitted and pushed 7e0c9a2 to main and 00a4c7e to 11.x. Thanks!
Thinking about this now, I think a CR with a notice that the setting will be respected in hook discovery would be good.
Comment #41
berdirCreated https://www.drupal.org/node/3608804