Problem/Motivation
An audit of the 4.x branch before its first beta found defects across the submodules. Each one below has a kernel test that fails on 4.x and passes with the fix. None of the fixes changes behaviour that a working site relies on; the defects whose fix would are described in a follow-up issue instead.
Domain
- The site could lose its default domain: unticking "Default domain" on it left none, a save that made another domain the default but was then refused (duplicate hostname) had already demoted the previous one, and the delete form was reachable for the default. Anonymous visitors of an inactive domain then got a fatal error.
- The edit form let the default domain be saved inactive, which redirected its anonymous visitors to the same URL in a loop.
- Users with "edit assigned domains" or "create domains" could make a domain the default from the edit form, and the inline Make default/Enable/Disable route only checked update access. The domain list already hid those operations from them.
- Enabling a domain did not clear the cached redirect away from it, nor any other cached non-HTML response: only the rendered tag was invalidated.
- "Paths that should be accessible for inactive domains" was read when the router was built and compared with route patterns, so an added path stayed forbidden until a rebuild, and a listed path like /user/reset/1/... never matched. Under a domain path prefix, the login page of an inactive domain redirected.
- Access to domain records read the user's assignments but was cached per permissions only.
- Domain tokens and links to a "variable" scheme domain lacked the url, url.site and domain cache contexts they depend on.
- Hostname validation accepted ports like :0, :99999 or an empty one, a trailing newline, and URL syntax (@ / ? # spaces) in non-ASCII mode; uppercase path prefixes passed the form in non-ASCII mode.
- Saving the domain list saved every domain even when nothing moved.
- The server debug block showed status and default inverted; "Jump to..." in the navigation block was not translatable.
Domain Access
- The Add/Remove domain bulk actions only checked update access on the entity. An editor who may not edit the Domain Access field could still change the domains of content from /admin/content, an editor with "publish to any assigned domain" could put content on domains the field widget does not offer them, and a user could make themselves editor of a domain on their own account. The actions now follow the field access and the widget's rule.
- Node access, node create access, the views route access check and the views access plugins read the user's domains, but their results either did not vary by them, so an answer cached for one editor could be served to another with the same roles, or varied per user, which keeps every page showing them out of the dynamic page cache.
- Changing per-bundle grants or field removal in the settings form did not flag a permissions rebuild.
- Per-type domain permissions stayed in roles after their content type was deleted.
- Small fixes: the all_affiliates views requirement, the field sort comparator, dead action cleanup code.
- The documentation now describes "publish to any domain" as the grants apply it: with "edit/delete domain content" it edits and deletes content on every domain.
Domain Alias
- On a non-default environment, saving a domain from code, or making another domain the default, wrote the environment alias hostname into the domain configuration.
- DomainAlias::getDomain() never found the parent domain, so the "domain aliases for assigned domains" permissions never worked.
- Resolving a hostname ran one alias query per candidate pattern, up to 93 for a five-label host, on every non-exact request.
- Alias changes did not clear cached redirects; alias ports like :1e3 or :-1 were accepted.
Domain Config, Domain Config Language, Domain Config UI
- The 2.x override migration skipped every site without the language module, so their per-domain overrides were never read. It now runs on every site, and a new update migrates the sites that already skipped it.
- Renaming a configuration moved its per-domain, per-language override to a collection named after the langcode.
- The language override dropped the language cache context when a domain was active, and failed with no language.
- "Disable domain configuration" always failed; the inline action failed without a destination; inspecting an unknown domain or configuration was a fatal error.
Domain Content
- The "Affiliated content" and "Affiliated editors" overviews had no cache metadata: the dynamic page cache could serve one editor's list of domains to another editor with the same roles, and their counts did not change until a cache clear.
Domain Source
- The "Domain source = Active domain" views filter did not vary by domain; a post update refreshes the views saved before.
Proposed resolution
Fix each defect where it happens, keeping every public method and constructor:
- The rules for making a domain the default, enabling, disabling and deleting it live in the domain access handler as access operations. The domain list, the edit form, the inline route and the actions all ask it.
- The previous default is demoted after the new one is saved. A domain is never redirected to itself.
- Domain and alias changes invalidate http_response as well as rendered, through one shared helper.
- The inactive domain check runs on every route and compares both the route pattern and the path with the setting at request time.
- Domain::preSave() keeps the registered hostname when negotiation replaced it by an alias, which replaces five scattered workarounds.
- Answers that read the user's domains vary by two new cache contexts: user.domain_admin (the domains the user administers) and user.domain_access (the domains the user is assigned to, and the "all affiliates" flag). Users with the same domains and roles share cached output, and pages stay in the dynamic page cache, which the user context keeps them out of. Each context is computed once per loaded user.
- A bulk action checks its domains once per operation, not once per selected entity.
- The 2.x migration service moves to domain_config; the previous service name stays as an alias.
Performance, measured against 4.x on the same codebase: no database query added in any measured scenario (node page, login, alias host, node access, domain access and list, alias lookup, domain save); page requests within noise; the alias lookup four times faster. The bulk action access check is about a third slower because of its new field and domain checks.
Remaining tasks
- Review the merge request.
- Release notes: unticking "Default domain" on the default domain now keeps it the default; the Domain Access bulk actions need access to the Domain Access field and only assign the domains its widget offers; existing views using the "Active domain" source filter are saved again by the post update.
User interface changes
The "Default domain" checkbox shows only to users who may make a domain the default, and is disabled on the default domain. The edit form refuses to make the default domain inactive. The Make default, Enable, Disable and Delete operations follow the same rules on every page.
API changes
None removed or changed. New: the default, enable and disable access operations of domain records, Domain::isValidPathPrefix(), DomainHostnameConstraintValidator::isValidPort(), the domain_config.override_migration service, the user.domain_admin and user.domain_access cache contexts and their base class UserDomainsCacheContextBase.
Data model changes
None. domain_config_update_10004() and domain_source_post_update_active_domain_filter_context() migrate existing data.
AI-Generated: Yes (Claude Code ran the audit, drafted this issue summary, and wrote the fixes and their tests. I reviewed them, and each new test was confirmed to fail on 4.x and to pass with the change.)
Issue fork domain-3642166
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3642166-fix-the-defects-4.x-default-query
changes, plain diff MR !516
- 3642166-fix-the-defects-3.x
changes, plain diff MR !510
- 3642166-fix-the-defects-3.0.x
changes, plain diff MR !511
- 3642166-fix-the-defects
changes, plain diff MR !508
- 3642166-fix-the-defects-4.x-post-update
changes, plain diff MR !512
Comments
Comment #3
mably commentedComment #4
mably commentedComment #6
mably commented