#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.