-
Notifications
You must be signed in to change notification settings - Fork 639
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 data was stored somewhere, so it could be consumed by the Element API #1231
Comments
We're keen to use Craft CMS as a headless CMS but "live preview" would be sorely missed. Clients absolutely love it. Is this on the roadmap? Related issue on CraftQL: markhuot/craftql#31 |
We’re tossing around some ideas for it. There aren’t any really obvious answers though, since Craft isn’t the one serving the rendered content when it is used as a headless CMS. One option could be that we implement custom Live Preview targets (#1489) where you supply a URL that Live Preview should POST to with all the field data. |
@oddnavy and i are working through this together, and to try and help stimulate further discussion, i'll use some examples of what we're doing and what we've tried. Take a section that includes the following fields:
Under normal headless usage, our custom web app receives a request and makes a query to Craft (using the CraftQL plugin) for an Entry by uri. When we are logged in as a content editor and press the Live Preview button, we end up generating a POST request from Craft to our custom web app with the following data:
Without modifying our custom web app, it will continue to query Craft for an Entry by uri and show the most recently published version. We want to address this... One option we have is to modify the custom web app to just use the POSTed data. This works ok for plain text fields, but would require us to write logic to resolve the related data (e.g. Instead what i think needs to happen is to pass the live preview token ( I suspect this is currently difficult if the live preview data isn't persisted; could the live preview data be persisted in a similar way to drafts or as a "special" entry version? If that were the case, i can imagine this being really easy for the CraftQL plugin to implement. Appreciate your internal discussion and feedback already, and i'd happily get involved in any way i can. Thank you! EDIT: Just to be clear -- it's not so much the Live Preview target, since we can already get the POST data inside of our custom web app... it's the resolution of all of the related data and Craft functionality that is tripping us up. |
Yeah, so that’s another route we’re also considering, but Live Preview is available to more than just Entries, so it’s something we’ll need to solve for all element types. Plan for this would be:
We’re planning on making some major content modeling & storage changes in Craft 4, so that will be a good opportunity to address these. (Not sure on the ETA for that though.) |
Guys, I have a well exercised back end which takes care of the data problem, and two front end architectures. The second one, done in past two weeks for Gatsby, is where I want the delivered plugin to go for all platforms, for good reasons. I'm moving faster than I should and nearly can...but the principle should go beyond entries as Brandon wants to. I'll try to get a little movie together for comment, maybe tomorrow late or if not Friday, showing a Vue SPA app and a Gatsby-React site as applications, editing in the expected Craft way, and on the web. I know you want to rush, but I suspect patience would be a virtue. And now it's very late here. |
I wanted to provide you the film as promised -- if a little after eleven.
-- that's a dropbox mp4 that'll play on your browser, best if you click lower right to make it full screen Of course I'll do a better film, with narration (!) and so forth. This is what I could come up with on short notice, while not totally interrupting the process that's getting Live Vue to the plugin store. p.s. I did consider some nice background music, to take the curse off this if I could not do more tonight, but copyrights; and anyway quiet seems welcome… |
...and, well, I had a look through the uploaded video just to be sure, and noticed then that I did all the Gatsby parts with that site in devMode on, so that CraftQL and hence app screen updates were really slowed by all its extra checks. I had anyway wanted to compllment @markhuot again on how much he's brought the performance up recently, and that saved the occasion, as I’m not going to do this over again tonight. How I handle the various latencies that will crop up in wider use is an interesting topic, anyway, for future. Natalia Lafourcade has my ear for this evening…. And this may prove a useful beginning: https://narrationsd.com/docs/live-vue/ |
Thanks, @brandonkelly! Having Live Preview would make Craft an even better candidate when choosing a headless CMS. Hopefully it makes it into the Craft 4 release. @narration-sd is your plugin available online for testing? |
David, I've taken a deeper look at Inlight, and it certainly looks like Tony has a strong team, not to say a great agency title. I note that React has a big presence, and this guides some thinking. I'm open to learning more about the project frame you guys would like to work at present, as this will influence timing -- depends on what you need. I've dug up an email for you, and will send a note. As far as the back-end plugin which does all the work, this is as proving as robust as ever. On the weekend an idea for the browser frameworks side drew me into coming up with something that will be a great improvement all around, particularly for the most challenging cases, and also simplifying. It's halfway to being implemented to prove this out. With this result, status for a beta is near, and as it's sensible, that's where Inlight could have a look. Clive |
This has been added for the next 3.2 Alpha release! Preview requests will have a |
Hey, Brandon @brandonkelly, congrats on getting this to go! I was watching your notes flash by last night while doing infrastructure on getting the completed Live Vue plugin's support ready for the Store, and with a little back of the envelope this morning, looks like it's going to mesh right in, with a very comfortable transition. All the things Live Vue does to enable essentially unmodified SPAs to show previews just by themselves (!) remain essential, and with the addition of Hal that came out of the beta, should even be fun to use. In summary, as smooth as with Twig. Your draft entries will mean I don't have to maintain and watch robustness/resilience on the HiddenRecord object manager that does fine at present, and will become an interface. Great, actually! Really happy to hear what you've done handles recent questions about Matrix and probably related aggregating types also - Live Vue's architecture just follows what you put in previews already, so the more reliable/resilient, of course the better, and for Craft. So, there are lots of connections, aren't there, given the FRs you're closing etc.. A couple of thoughts around the edges:
Enough am sure, but always impressed with the energy you and the team bring to getting closures, each time very good and thoughtful ones, on all that matters in Craft, Brandon. Clive |
Glad to hear that, @narration-sd! |
Just to let you know, this all worked, after two sessions on a Saturday. It's not in the version that's about to release, but is prototyped on a branch and doing previews nicely, with Vue this time, so now suiting 3.2 and its changes is validated. One or two highly interesting things to figure out along the way...but result is simple, which is great. A p.s. @brandonkelly, that following your ongoing support comments can be very useful...! |
One of the best features of Craft CMS is the fact that it allows for "live preview". Unfortunately, this is only possible if the front-end is build using the Twig template engine. If you are creating a SPA using their Element API, there is no way to access this data to simulate the same experience.
The text was updated successfully, but these errors were encountered: