#107060preview.js crashes when previewing workspace-only pages (no live counterpart)
Description
Problem
In TYPO3 v13.4.14, when previewing a newly created page in a workspace (i.e., a page that has no counterpart in the Live workspace), the JavaScript file “EXT:workspaces/Resources/Public/JavaScript/preview.js” crashes due to a missing DOM element.
This breaks the frontend preview interface: the “Send to Stage” or “Discard” buttons dont work, and one error appears in the browser console.
Steps to Reproduce
- Create a new workspace
- In that workspace, create a new page (that does not exist in Live!)
- In the Workspaces module, click the “Preview” icon for that new page
- Observe: the page renders, but preview controls are broken
JavaScript Error
Uncaught TypeError: this.elements.activePreviewMode is null
at PreviewView.setPreviewModeInView
Cause
In the Fluid template for the workspace preview:
EXT:workspaces/Resources/Private/Templates/Preview/Index.html
<f:if condition="{liveUrl}">
<f:then>
<span class="t3js-active-preview-mode" ... />
</f:then>
<f:else>
<span><f:translate key="LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:info.newpage.detail" extensionName="workspaces" /></span>
</f:else>
</f:if>
In the `<f:else>` branch, the required element with class `.t3js-active-preview-mode` is missing.</f:else>
However, in preview\.js, the code assumes that element is always present:
this.elements.activePreviewMode.dataset.mode;
This causes the JS to throw a TypeError when there is no Live page.
Suggested Fixes
Either:
- Always render the `.t3js-active-preview-mode` element in the template, even if no live page exists (e.g. with data-active-preview-mode=“none”)
- Or update preview.js to include a null-check before using `this.elements.activePreviewMode`
Temporary Workaround
Overriding the Preview/Index.html template and injecting the following span avoids the JS error:
```html
New Page
```
This can be done via XCLASS or by copying the template during cache clear.
Affected Version
TYPO3 v13.4.14
Likely affects all TYPO3 v13.x versions where `preview.js` is used with workspace-only pages.
Reviews 2
History 57
-
Oliver Hader commented and changed status
NewAccepted 07/09/25, 08:35 -
Christian Kuhn commented 07/09/25, 17:56
confirmed.
-
Gerrit Code Review pushed patch set 1 for main to change 90039 status
AcceptedUnder Review 07/09/25, 18:35 -
Christian Kuhn commented 07/09/25, 18:36
Thank you! Great issue description and analysis!
-
Gerrit Code Review pushed patch set 1 for 13.4 to change 90040 07/10/25, 09:00
-
Christian Kuhn commented and changed status
Under ReviewResolved done0 %100 % 07/10/25, 09:15Applied in changeset commit:64baee1b50fcb22df7ff35816da3399ad02bde7c.
-
Benni Mack changed status
ResolvedClosed 12/02/25, 13:57
From my point of view, the JavaScript part should be robust enough and check for missing (
null) elements.