prismicio / prismic-gatsby

Gatsby plugins for building websites using Prismic
https://prismic.io/docs/technologies/gatsby
Apache License 2.0
313 stars 96 forks source link

Can't access data inside link fields when in a preview session #541

Closed kieranstartup closed 1 year ago

kieranstartup commented 1 year ago

Hey,

So this may be related to issue #422, but whenever I'm previewing a document and trying to access a link field, the field returns Proxy(Object), rather than the url. This is probably fine in a lot of cases, but in my case I'm trying to access a Vimeo mp4 file link, and then preview that within a <video>, so it's causing some issues where my client can't preview their changes.

Versions

Steps to reproduce

Add a link field to a slice. Add a link (in my case a link to a Vimeo mp4 video file).

What is expected?

Link field outputs the url, and displays the video.

What is actually happening?

Link field outputs Proxy(Object) instead of a url. I've tried following some of the suggestions in issue 422 with optional chaining but it's not getting me anywhere.

Screenshots

Screenshot 2023-08-10 at 17 57 14

Screenshot 2023-08-10 at 17 56 21

Let me know if you have any thoughts or need anything else to help replicate.

Thanks!

jodiedoubleday commented 1 year ago

Same issue here, links just aren't appearing in preview.

jodiedoubleday commented 1 year ago

is there any update/ fix for this issue @angeloashmore?

kieranstartup commented 1 year ago

@jodiedoubleday I don't think we'll be getting much support on the plugin going forward based on this blogpost. And it looks like Netlify laid off most of the Gatsby team too 😬

kb1995 commented 1 year ago

@jodiedoubleday @kieranstartup - would you recommend upgrading to v6?

My client and I have been waiting for v6 for half a year, but I'm a bit anxious upgrading it due to bugs like this and the lack of support from Prismic/Gatsby teams.

jodiedoubleday commented 1 year ago

@kb1995 I think in all honesty it's still better to upgrade. There are a few small bugs that need fixing but nothing serious, it's soo much faster to preview large repos.

kieranstartup commented 1 year ago

@kb1995 Yeah I second that, it's definitely still better to upgrade. As a heads up, the docs are all here now rather than on the Prismic site.

angeloashmore commented 1 year ago

Hey everyone, Proxys are necessary to support the content relationship document property during previews. You will see a Proxy object when console.log()ing a field, but the data is still in it.

You can confirm this by logging properties of the object rather than the whole object. For example:

console.log(myField.url)

Alternatively, you can inspect Proxys by opening the [[Target]] value in Chrome's DevTools:

image

@kieranstartup There was a bug in how links were processed during previews that made the url property always return null. That may have been what you were experiencing.

Could you upgrade to v6.0.1 and let me know if your problem was resolved? Thanks!

kieranstartup commented 1 year ago

Hey @angeloashmore,

Thanks for implementing this, I've just tested and it works perfectly.

Really appreciate it!