Issue Bug Closed

#107060preview.js crashes when previewing workspace-only pages (no live counterpart)

David Schneider 07/09/25, 08:19 updated 12/02/25, 13:57

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

  1. Create a new workspace
  2. In that workspace, create a new page (that does not exist in Live!)
  3. In the Workspaces module, click the “Preview” icon for that new page
  4. 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:

  1. 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”)
  1. 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

  1. Oliver Hader commented and changed status New Accepted 07/09/25, 08:35

    From my point of view, the JavaScript part should be robust enough and check for missing (null) elements.

  2. Christian Kuhn commented 07/09/25, 17:56

    confirmed.

  3. Gerrit Code Review pushed patch set 1 for main to change 90039 status Accepted Under Review 07/09/25, 18:35

  4. Christian Kuhn commented 07/09/25, 18:36

    Thank you! Great issue description and analysis!

  5. Gerrit Code Review pushed patch set 1 for 13.4 to change 90040 07/10/25, 09:00

  6. Christian Kuhn commented and changed status Under Review Resolved done 0 % 100 % 07/10/25, 09:15

    Applied in changeset commit:64baee1b50fcb22df7ff35816da3399ad02bde7c.

  7. Benni Mack changed status Resolved Closed 12/02/25, 13:57