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

Live Preview not updating with Neo field #21

Closed
louderthan10 opened this issue May 24, 2016 · 21 comments
Closed

Live Preview not updating with Neo field #21

louderthan10 opened this issue May 24, 2016 · 21 comments
Milestone

Comments

@louderthan10
Copy link

First. This plugin changes everything. So well done. Thank you!

I've just built a pretty robust Neo-based install using our internal Live Wires prototyping library. It works amazingly well, there' just one small hitch we're running into… Live Preview doesn't refresh when editing the Neo field.

Possibly related: I had the same issue with another Craft install with the Matrix field when Eager-loading was implemented. Removing eager-loading helped. Same issue as this: http://craftcms.stackexchange.com/questions/8879/issue-with-matrix-type-property-and-live-preview

Not sure if it's just the sheer size of this field, or something else.

Feel free to try out the install for yourself (auto resets every night): http://demo.livewires.io/admin u:admin p:password)

Also here's the repo if you want to see the code used: https://github.com/louderthanten/craft-editorial-system (this field uses the _content.html file and _content folder to render the field).

@benjamminf
Copy link
Contributor

Thanks man, appreciate it!

I think I may have found your problem. Looking at the source for pages/default, I see you're caching the content inclusion, unless dev mode is enabled. Live preview, regardless of your config settings, will not render in dev mode. So the reason your Neo field isn't updating is because it's being cached in live preview mode.

Try this instead:

{% cache unless craft.config.devMode or craft.request.isLivePreview %}
    {% include '_content' %}
{% endcache %}

@louderthan10
Copy link
Author

Thanks for the quick reply and suggestion.

I tried it out (updated in the demo site, and cleared cache). But still running into the same problem. It's weird because it's only the Neo field that doesn't get updated. Trying the following without saving or refreshing the entry:

  1. I edit a standard text field (Heading or Subhead) and Live Preview refreshes.
  2. I edit the Neo field, nothing happens.
  3. I edit another standard text field (Heading or Subhead) and Live preview refreshes that text… and the content from the Neo field still doesn't show up.
  4. It's only after I save the entry that the Neo field shows up in the page.

@benjamminf
Copy link
Contributor

benjamminf commented May 25, 2016

Monitoring the console, I can see changes to the Neo field are being detected, as AJAX requests are being sent to the server to update the preview. The fact that the Neo field updates after saving still leads me to believe it still might be a caching problem, since caches get cleared after saving an element, so it fits the behaviour. Although I admit with the added live preview check, I don't understand how it could still be a problem.

I know it's probably annoying, but do you think you could try removing the cache tags to see what happens?

@benjamminf
Copy link
Contributor

Okay so I've set up a local version of the site, and removing the cache tags doesn't solve the problem. I'm going to have a play around with it then get back to you.

@benjamminf
Copy link
Contributor

Seems you've discovered a bug with Neo! Live preview fails when you modify the element criteria model on the field. Removing the .level(1) filter will fix the problem, but it's not a solution obviously. I'll make fixing this a priority, and hopefully have it sorted some time today.

@benjamminf
Copy link
Contributor

Not only that, you've discovered a bug with Craft's Matrix field too! Seems it has the same issue. I might go open a bug report with them.

@louderthan10
Copy link
Author

That's super interesting. I think it must be related to that issue I mentioned in the original post above… having similar trouble with Matrix when eager loading was applied. I ended up removing eager loading in Live Preview to get to work. Must have been related to the .find filter in that case.

@benjamminf
Copy link
Contributor

benjamminf commented May 25, 2016

Yeah that's probably what it was.

Looking into this issue... this is not an easy fix. All you can do when preparing criteria models for live preview is manually pass the blocks with it. All the filtering done by the element criteria model is done against the database, which explains why it doesn't live update.

I wonder if P&T already know about this issue, and have just ignored it since it would require a pretty big rearchitecture of their element criteria model. I know they're ditching it in Craft 3 for a newer approach called Element Query, so maybe they'll fix it then.

In the meantime, I'm going to look for ways around this. For simpler, common filters like level, this might not be too difficult, but things that require the context of a database like relatedTo, it's not looking likely.

@louderthan10
Copy link
Author

I was afraid of something like that. Getting it to work around level is definitely enough for me and how I would use it 90% of the time… (probably 99% the time considering it only affects Live Preview).

Hopefully they fix it in 3.0. :)

@benjamminf
Copy link
Contributor

Good news! I managed to figure out a pretty clean workaround. I have the level filter working in live preview, but I want to extend it to other filters, as well as the children attribute on blocks.

@benjamminf
Copy link
Contributor

benjamminf commented Jun 5, 2016

I'm calling this done for now. I've implemented everything in the current API except for relatedTo and search. I think it's possible to implement these as well but it'd take a while. Also, comparison-based level queries (eg. '>=1') are still unimplemented. But everything else is working.

This will be available in the next release, which will be released mid-late next week was released today.

@louderthan10
Copy link
Author

Fantastic. Work perfectly for me. Thank you!

@louderthan10
Copy link
Author

Dang it. Looks like a recent Craft update breaks Live Preview and Neo again. This time top level blocks are updated, but children aren't.

Neo works fine in Craft v2.6.2791

When I update to v2.6.2794 (and v2.6.2793), Neo stops live previewing.

Tried in multiple installs. Also tried different Neo versions in both v2.6.2791 and v2.6.2794 with same results.

:(

@benjamminf
Copy link
Contributor

@louderthan10 Alright fixed it. It was a minor change to their element criteria model that resulted in this bug. They had changed the count() method to always access the database instead of counting the matched blocks cache. Which meant child blocks couldn't be detected so it fell back to a database call there as well. Not sure why this change was made, as the Craft changelog doesn't say anything relating to this change. Oh well, I've fixed it now, and will make a new release for Neo very soon. If you can't wait, grab a copy of Neo_CriteriaModel.php from the dev branch and replace the old one.

@louderthan10
Copy link
Author

Wicked. Thanks!

@leevigraham
Copy link
Contributor

This is happening because Matrix will only show the non-live blocks so long as you don’t set any Matrix parameters in your template. As soon as you tell it to only show blocks of a certain type, it no longer feels confident that the blocks it was going to output are the right ones, so it will dump them and run a new DB query.

http://craftcms.stackexchange.com/a/8880/963

@shealan
Copy link

shealan commented Jan 15, 2017

Is this still an issue?

I just installed the current release of Craft and Neo and I am not seeing anything in live preview even when in dev mode.

I have a pretty standard nested configuration. The component with data is an entries field type.

image

@shealan
Copy link

shealan commented Jan 15, 2017

Update: I replaced the file mentioned earlier and it works. Assumed it would had already been merged in as it was a while ago. Is there a new version planned soon? Or has development halted until Craft 3 is released?

@benjamminf
Copy link
Contributor

benjamminf commented Feb 12, 2017

@shealan There has been 1.4.0 on the master branch without an official release since late last year, but it had a bug with the Neo-to-Matrix conversion feature that I only just got around to fixing. Since then I've fixed a number of issues, most of which have been pushed to the master branch, which would explain why it's probably working for you now. I'm releasing a 1.4.1 version very soon.

Since late last year life has essentially caused my OS work to come to a complete halt. I'm just starting to get back into regular development again, but I think soon most of my time will be spent on the Craft 3 rebuild of the plugin.

@shealan
Copy link

shealan commented Feb 12, 2017

@benjamminf thanks for the update. Your work is really appreciated. Looking forward to seeing the Craft 3 update!

@florianmatz
Copy link

Had the same problem with live preview on craft-neo 1.41. Disabling eager loading explicitly for the preview helped:

{% if craft.request.isLivePreview %} {% set contents = entry.f_contents.level(1).find() %} {% else %} {% set contents = entry.f_contents.level(1).find({ with: [

@benjamminf

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

No branches or pull requests

5 participants