Skip to content
New issue

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

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

Already on GitHub? # to your account

Live Preview doesn't update eager-loaded matrix fields #1787

Closed
pierrestoffe opened this issue Jun 22, 2017 · 7 comments
Closed

Live Preview doesn't update eager-loaded matrix fields #1787

pierrestoffe opened this issue Jun 22, 2017 · 7 comments
Assignees
Labels
bug matrix 🕶️ features related to Matrix fields severity:minor Cosmetic issues or bugs with simple workarounds

Comments

@pierrestoffe
Copy link

Description

I'm encountering this bug where eager-loaded matrix fields are not updated in Live Preview. It will always show them the way they were when the entry was first opened.

This means that if my matrix field is empty when the page opens and I then enable Live Preview, the section related to the matrix will always be shown empty in the Live Preview. If I was to have some content in the matrix when the page was opened, then that content would always be shown, whether I remove the block or add a new one.

I've read about the dirty workaround described here: https://craftcms.stackexchange.com/questions/15769/find-not-working-with-live-preview but it really is a pain.

Is it in your short-term plans to work on this issue? Isn't it possible to simply disable eager-loading in Live Preview mode? Wouldn't it make more sense?

Steps to reproduce

  1. In the CP, open an entry where the template contains eager-loaded matrix fields
  2. Open Live Preview
  3. Edit the matrix blocks
  4. The changes won't be visible in Live Preview

Additional info

  • Craft version: 2.6.2982 (Pro)
  • PHP version: 7.0.18-1+deb.sury.org~trusty+1
  • Database driver & version: MySQL 5.5.55-0ubuntu0.14.04.1
  • Plugins & versions:
    • Focal Point Field 1.0.2
    • LJ Cookies 1.0
    • Sprout Fields 2.1.1
    • SuperSort 1.2.0
@brandonkelly brandonkelly self-assigned this Jun 29, 2017
@brandonkelly brandonkelly added severity:minor Cosmetic issues or bugs with simple workarounds and removed severity:minor Cosmetic issues or bugs with simple workarounds severity:normal Bugs that affect typical usage labels Jul 7, 2017
@brandonkelly brandonkelly added the matrix 🕶️ features related to Matrix fields label Feb 26, 2018
@mildlygeeky
Copy link
Contributor

@brandonkelly do you know if this is also an issue in Craft 3? As well, I would dispute this as being a minor bug, as Live Preview is a pretty big selling point of Craft and having properly-coded Matrix fields not work with it is a big issue (and disabling eager loading would make Live Preview quite slow on complex pages).

@brandonkelly
Copy link
Member

@mildlygeeky Yeah almost definitely still an issue in Craft 3. It’s complicated due to the current implementation of Live Preview, otherwise we would have fixed it. But we have a plan that will fix things like this and #2801:

1. make drafts/versions a system-wide thing, where a single “draft” could include more than just one entry/element (#2116)
2. implement automatic draft creation & auto-draft-saving when editing elements (#1034)
3. get Live Preview to show the stored draft content rather than unsaved posted content, driven by normal element queries

@stephent2c
Copy link

Hey @brandonkelly. We have a number of large sites running Craft and a huge issue for the teams is that we do not have an auto-save feature while editors are creating entries. Do you have any lead time for when this may be made available?

@brandonkelly
Copy link
Member

@stephent2c sorry couldn’t give you a reliable ETA yet; at least 6 months out.

@domstubbs
Copy link

domstubbs commented Mar 12, 2019

This issue does make for quite a messy templating setup, assuming you don’t want to abandon eager loading and you still want previews to work reliably.

On my current project I’ve ended up with conditional queries like this, which at least gets things working, but it results in loads of deprecation warnings for live previews, since you end up iterating through element queries directly.

To work around that I’ve ended up adding custom |all and |first Twig filters that accept either arrays or element queries as inputs, which is working well so far and keeps the templates fairly clean, but it still feels a bit too hacky, and it’s not great to be relying on custom code for core functionality.

public function allItems($items)
{
    if (is_object($items) && method_exists($items, 'all')) {
        return $items->all();
    }

    return $items;
}

public function firstItem(\craft\web\twig\Environment $env, $items)
{
    if (is_object($items) && method_exists($items, 'one')) {
        return $items->one();
    }

    return twig_first($env, $items);
}

@brandonkelly
Copy link
Member

We’re planning on implementing #1787 (comment) in 3.2 or 3.3.

brandonkelly added a commit that referenced this issue May 17, 2019
Resolves #1021
Resolves #1034
Resolves #1135
Resolves #1231
Resolves #1489
Resolves #1787
Resolves #2120
Resolves #2325
Resolves #2669
Resolves #2909
Resolves #3349
Resolves #3392
Resolves #926
@brandonkelly
Copy link
Member

This has been resolved for the next 3.2 Alpha release!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug matrix 🕶️ features related to Matrix fields severity:minor Cosmetic issues or bugs with simple workarounds
Projects
None yet
Development

No branches or pull requests

5 participants