Skip to content

[BUGFIX] Guard version switcher against a missing selector - #1361

Open
CybotTM wants to merge 1 commit into
TYPO3-Documentation:mainfrom
CybotTM:bugfix/version-switcher-null-on-search
Open

[BUGFIX] Guard version switcher against a missing selector#1361
CybotTM wants to merge 1 commit into
TYPO3-Documentation:mainfrom
CybotTM:bugfix/version-switcher-null-on-search

Conversation

@CybotTM

@CybotTM CybotTM commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Problem

On the search results page (/search) the version-switcher script throws uncaught errors, which abort the remaining page scripts:

Uncaught TypeError: Cannot read properties of null (reading 'getAttribute')
Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')

versions.js looks up #versionSelect / #languageSelect and then calls versionSelect.getAttribute(...) unconditionally. Those elements only exist on manual pages — on the search results page versionSelect is null.

See it live (current production, not yet fixed — open the browser console): https://docs.typo3.org/search/search?q=openai&filters%5Bpackage%5D=netresearch/nr-llm

Fix

Bail out early in versions.js when the switcher is absent. Adds a regression test and rebuilds theme.min.js (grunt js).

Verification — console before / after

Headless Chromium against the live page above, routing theme.min.js to the build from this PR:

BEFORE (production theme.min.js)
  - Unexpected token 'export'                                    <- typo3infrastructure/universe (separate, internal)
  - Cannot read properties of null (reading 'addEventListener')  <- versions.js
  - Cannot read properties of null (reading 'getAttribute')      <- versions.js

AFTER (this PR's theme.min.js)
  - Unexpected token 'export'                                    <- unchanged (universe; out of scope here)

Both versions.js null errors are gone; only the unrelated universe error remains. npm test -> 28 passed.

Note

The Unexpected token 'export' comes from the typo3infrastructure/universe bundle (outside this repository) — a separate issue for the infrastructure maintainers, not addressed here.

@CybotTM
CybotTM marked this pull request as draft July 31, 2026 12:38
@CybotTM CybotTM added the bug Something isn't working label Jul 31, 2026
@CybotTM
CybotTM marked this pull request as ready for review July 31, 2026 17:46
versions.js assumed every page has #versionSelect and #languageSelect and called
versionSelect.getAttribute() unconditionally. On pages without the switcher (e.g.
the search results page at /search) versionSelect is null, so the script threw
"Cannot read properties of null (reading 'getAttribute')" (and, further down,
"reading 'addEventListener'"), aborting the remaining page scripts.

Bail out early when the switcher is absent. Adds a regression test and rebuilds
theme.min.js.

Signed-off-by: Sebastian Mendel <github@sebastianmendel.de>
@CybotTM
CybotTM force-pushed the bugfix/version-switcher-null-on-search branch from fb4e5a1 to c17fda4 Compare July 31, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant