Skip to content

Statistics backend fails after container ID removal

Commit / Cause: 92033a84c3150c496007afbf4dbcbda834fb4776

Module: Backend → Statistics

Summary

After the above commit, the ID of the “no data found” container was removed from the template. The JS (statistics.es.js) still queries this element via document.getElementById(...) and accesses .style. Because the element no longer exists, getElementById returns nullJS error → the Statistics view does not render.

Console error:

statistics.es.js?bust=42b6d310aacc2d063f56f913629b6f0390baae11:20802 
Uncaught TypeError: Cannot read properties of null (reading 'style')
    at request.onload (statistics.es.js?...:20802:62)

Expected behavior

The Statistics module loads without JS errors. If no data is available, the “no data found” message is displayed.

Actual behavior

The JS throws a null-reference error when accessing .style on a missing element; the Statistics screen remains blank.

Steps to reproduce

  1. Install latest main (including commit 92033a84...).
  2. Open TYPO3 backend → SG Cookie Optin → Statistics.
  3. Open the browser console and reload.
  4. Observe the error; the Statistics view does not render.

Root cause

  • The template Resources/Private/Templates/Statistics/Index.html no longer provides the container ID expected by the JS.
  • The JS still queries a hard-coded ID (e.g., statistics-no-data-found) and immediately accesses .style on the result.
  • Without the ID, the query returns null, causing a TypeError.

Proposed fixes

Option A (minimal, restore template ID): Re-add the ID so existing JS continues to work unchanged.

Patch (tested):

--- Resources/Private/Templates/Statistics/Index.html
+++ Resources/Private/Templates/Statistics/Index.html
@@ -70,7 +70,7 @@
 
 				<!-- Render the "no data found" flash message at the bottom of the page -->
 				<f:flashMessages queueIdentifier="noDataFoundMessage" as="noDataFoundMessages">
-					<div class="typo3-messages">
+					<div class="typo3-messages" id="statistics-no-data-found">
 						<f:for each="{noDataFoundMessages}" as="flashMessage">
 							<div class="callout callout-{flashMessage.severity.cssClass}">
 								<div class="media">

Option B (make JS defensive, additionally or alternatively): Add a null check and a selector fallback (e.g., .typo3-messages) so the module doesn’t hard-fail if the ID is missing:

const el = document.getElementById('statistics-no-data-found') 
         || document.querySelector('.typo3-messages');
if (el) {
  el.style.display = 'block';
}

Environment

  • TYPO3: 12.x
  • PHP: 8.2
  • sgalinski/sg-cookie-optin: 7.0.11

Impact

The Statistics backend view is broken and does not display.

Workaround

Apply the above template patch locally or add the defensive JS check.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information