Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x]: Live Preview not reflecting unsaved changes made without live preview #16967

Open
mnlmaier opened this issue Mar 27, 2025 · 7 comments
Open
Labels

Comments

@mnlmaier
Copy link

What happened?

Description

This is kind of a weird title, but I am facing the problem that live preview is not properly updating when making changes with live preview closed.

Live Preview itself is working fine when changes are being made while Live Preview is open.

Steps to reproduce

  1. Place a new content module on a site (in this case, a Text Input inside a Matrix field)
  2. Type "Headline goes here" in it
  3. Open Live Preview and notice that the preview renders properly
  4. While Live Preview is open, change the text to "Headline from Live Preview goes here" and see the changes being reflected just fine
  5. Close live preview, notice that the Text Input field is updated with the new Text from Live preview
  6. With Live Preview closed, change the text to "Headline from outside Live Preview goes here"
  7. Don't save the entry
  8. Open Live preview and notice that it's still showing the old text without "outside", both in the Text Input Field and also in the rendered preview
  9. Close the live preview again, notice that the value in the text field still correctly shows the new value
  10. Save the entry
  11. Open Live preview again, notice the new text appearing

Expected behavior

I guess, I'd expect Live Preview to reflect the current content state I entered, no matter if I saved it or not.

Actual behavior

Some kind of discrepancy, see Steps to Reproduce.

Craft CMS version

Craft Pro 5.6.10.2

PHP version

8.2.28

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Please note that we are using MatrixExtended — https://plugins.craftcms.com/matrix-extended?craft5

@mnlmaier mnlmaier added the bug label Mar 27, 2025
@i-just
Copy link
Contributor

i-just commented Mar 27, 2025

Hi, thanks for getting in touch! Which view mode is this matrix field using?

@mnlmaier
Copy link
Author

Hi @i-just, thanks for the quick reply! The following view mode is used:

Image

@i-just
Copy link
Contributor

i-just commented Mar 28, 2025

Thanks! I’m unable to reproduce this. In step 8, I see the text from step 6. I recorded a video based on your steps (only using much shorter text). Does it look like what you’re doing when you encounter this error?

Screen.Recording.2025-03-28.at.09.40.58.mov

Could you enable safeMode and check if you’re still experiencing this behaviour?
What do you have set in the “Preview Targets” for the section this is happening in?

@mnlmaier
Copy link
Author

mnlmaier commented Apr 1, 2025

Hi @i-just — thanks for your effort in reproducing this. You are following the same steps as me, weird that it's working for you, so it seems to be an issue on our end. I have ruled out the Matrix Field being an issue, since it happens in a regular text field as well.

Tried digging a bit deeper and, when changing the content an existing and already filled input field after a hard refresh, the changes are also not reflected in live preview.


I also tried re-saving the entry, since it only started happening after the Craft 5 Update.

For the Preview Target, we did configure the following:

Image

I also can see some warnings on the console which I assume might be related. Those warnings come up when i press the live preview button.

Image
Image


I also tried turning on safe mode on staging, which threw some template errors, which in turn prevented me from digging deeper. The previous developers seem to have used ??? instead of ?? in Twig, which might have become an issue by now. Can you confirm that this is not a valid operator?

At least I can see why hidden template errors might cause proper rendering to fail — I cannot see though why it only affects updating and not initial rendering.

@i-just
Copy link
Contributor

i-just commented Apr 1, 2025

Thanks for providing further info!

??? is not listed in the Twig’s documentation, but you can use it if you install, e.g. the Empty Coalesce plugin.

I also see the warnings you see (about the live region and modal object, but they don’t affect the preview capabilities).

Would you be able to simplify the template(s) used by the entry that exhibits the issue you described? For example, try to display only the entry title and the field inside the matrix entry (block) you’re changing.
Also, you mentioned trying the safeMode on staging. Are you experiencing the same behaviour when running the site locally?

@mnlmaier
Copy link
Author

Hey @i-just — thanks for getting back to me, and sorry for the delay. I’ve started digging deeper into the issue.

It looks like the Empty Coalesce plugin is used quite heavily throughout the project. That would explain why enabling safeMode breaks the templates — as far as I understand, the plugin doesn’t run in safeMode, right? I can confirm that toggling safeMode locally or on staging doesn’t make a difference — the site breaks either way due to the missing plugin.

So, to rule out other issues, I stripped the template down to the bare minimum and re-tested in safeMode:

<div>
  {{ entry.entryCustomH1 }}
</div>

No change, still not working. This was the whole template.

I was trying this out locally, when I spotted another weird behavior: Using the Matrix Field, I added a new content module to the page, called "Headline", which is a single text field. I moved it from the end of the content to the beginning of the content and filled it with text. When starting the preview mode, the text field was there — at the bottom of the page, and empty, seemingly just ignoring everything besides the initial placement.

When adjusting the Text (not the placement) while in Preview Mode, the placement resets back to the placement being shown in preview mode, but the text is correctly updated.

It feels like the entry’s field layout isn’t updating properly, or dirty states aren’t being registered as expected. That said, I do see the expected network requests hitting the update-field-layout endpoint and returning 200 as you would expect.

Also worth noting: when opening Preview Mode (regardless of whether changes were made), no network requests are fired. Only when closing it — and only if something was edited — do the expected update requests go out.

I’m pretty sure this is something on our end rather than Craft itself, but maybe this behavior rings a bell? Any idea where I could dig next?

Really appreciate your help!

@brandonkelly
Copy link
Member

@mnlmaier Any chance you can send in your Composer files and a database backup to support@craftcms.com? If so we can try to reproduce using your site, and figure out what’s going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants