Preview is empty if launched manually after some input provided

Created on 2 August 2023, over 1 year ago
Updated 10 September 2024, 2 months ago

Problem/Motivation

When triggered manually after providing user input, the preview is blank instead of showing the input to date.

Steps to reproduce

  • Enable the same page preview, but have it set to not launch as soon as the form is loaded, for instance by manually closing it, and then reloading the form.
  • Put in some content, for instance the title and/or body field.
  • Manually trigger the preview using the Preview button.
  • Observe that the preview is initially empty, but once a refresh is triggered (for example by causing an input field to lose focus) the content appears as expected.

Proposed resolution

Ensure that any existing data is pushed into the tempstore when the preview is originally triggered.

πŸ› Bug report
Status

Needs work

Version

2.1

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada mandclu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mandclu
  • First commit to issue fork.
  • @dieterholvoet opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels
  • Status changed to Needs work about 1 year ago
  • So the fix doesn't work if I do this:

    1. Add new content
    2. In the iframe settings, disable Open preview by default
    3. Close and reload the page
    4. Type anything in the title and click the preview button

    The page is empty.

  • Okay, so this is weird. After the first time, it works correctly. Narrowed it down to being connected to the twig cache in some way, every time I flush it, the problem shows up.

  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

    Thanks for the error report @admirlju I'll try to reproduce and analyze.

  • So I've been digging a bit more. I'm not yet sure, but a few things I noticed, might help debug further.

    So I'm looking at the module file, and how the iframe and preview compiling is added in same_page_preview_form_node_form_alter.
    Noticed one thing, when the preview button is clicked but the pane is not open, this hook is called twice, the first time when it opens the pane, the UUID of the preview is wrong, and the second call uses the correct UUID and then displays the data. Now the weird part here, the UUID in $route_parameters in the first run does not match the UUID loaded in the pane, the second time it does match, so this first run never shows the correct preview node.

    So knowing this I went to check the PreviewPaneController.php, so the controller for the pane. An interesting thing happens here if I put a breakpoint, at any point, in the view method. It delays how long the pane needs to open, and this causes this second hook run to not update the preview.

    So what I'm assuming happens, after clearing the twig cache, the time to build the preview page is longer and this second call happens before the pane preview page is displayed. However, when the node cache is built, the pane display is fast enough for the second call to refresh the page.

  • Also, elements that update the preview on blur, open a preview pane that is empty and use the wrong UUID. So this is a bigger problem in general.

  • πŸ‡±πŸ‡§Lebanon christina_abboud

    I created a patch to solve this problem

  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

    I think..... Maybe we've already applied the fix that is in #11. Well, most of it. We aren't (in code) defaulting the display to the 'full' display mode. But doing so might be dangerous because it is possible to get rid of the 'full' display mode. So hard coding that feels dangerous.

    Can you retest? Is this still an issue?

Production build 0.71.5 2024