#111426Workspace preview: keep live and workspace frame scrolled to the same content element
Description
The workspace preview module shows a page twice, the live version (ADMCMD_prev=LIVE) and the workspace version (ADMCMD_prev=IGNORE), each in its own iframe. Both frames scroll independently. When an editor moves the slider between “Published version” and “Workspace version”, or uses the vbox/hbox split, the other frame shows a different part of the page. To compare a changed element, the editor has to find the same spot again by hand. On long pages this makes the slider hardly usable for reviewing changes.
There is no setting for this. workspaces.splitPreviewModes only selects the mode, and preview.js does not handle scrolling at all.
Steps to reproduce:
1. Switch to a workspace and change a text element far down on a long page (e.g. add two paragraphs).
2. Open the preview of the page (slider mode).
3. Scroll the workspace version to the changed element.
4. Move the slider to “Published version”.
Expected: the live version shows the same element, so the difference is visible directly.
Actual: the live version is still at the top of the page.
Proposed solution:
Sync the scroll position between both frames by content element, not by pixels, since the workspace version of an element may be longer or shorter than the live one.
- Each frame determines the content element at the top edge of the viewport (the anchor c<uid> rendered by fluid_styled_content, which is the live uid in both versions) and how far into it the viewport is, as a ratio of its height.</uid>
- The position is sent to the sibling frame via postMessage, so it also works when backend and frontend run on different domains.
- The receiving frame scrolls to the same relative point of the same element. If the element does not exist in that version (new, hidden or deleted in the workspace), it scrolls to just below the nearest preceding element that exists in both.
- Content elements rendered more than once on a page (records via “Insert records” repeat the same id) are matched by id plus occurrence.
- Programmatic scrolling is suppressed for a short moment to avoid ping-pong between the frames.
We run this as a site-level workaround on TYPO3 14.3: a frontend middleware adds a small script to responses with ADMCMD_prev=LIVE or IGNORE when a backend user is logged in. It works with the slider and both split modes. In the core it could live in the preview module itself plus a small frontend part, or as an option, e.g. workspaces.previewScrollSync = 1.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Fix this issue
Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch
- Commit message
-
[FEATURE] Workspace preview: keep live and workspace frame scrolled to the same content element Resolves: #111426 Releases: main