mattmilburn/strapi-plugin-preview-button

Autoupdate preview-URL, when slug-field is changed

Closed this issue · 7 comments

Thank you very much for this great plugin!
I encountert one small inconvenience:
I pass a slug-field to the preview-URL. When I change the slug, the preview-URL is not updated immediately.
The user has to reload the page, that the preview-URL gets updated.

Is there a way to fix this?

Hi @AndreasFaust I met the same issue than you because I am develop a custom slugify system based on lifycycle. Hop this can help #62

Hi @AndreasFaust Thanks for bringing this to my attention. I'll include this fix in an upcoming release 👍🏻

@AndreasFaust @Dupflo On closer inspection, I'm finding that the preview button does not update the URL unless you save the entity, which is intentional.

The preview button operates by sending your frontend app the data it needs in order to query the page/post from Strapi. So if you do not save the new slug value and your frontend app is going to query the page/post based on that slug, you need to save it before you preview it. In other words, you can only preview a page/post that has been saved in the database.

@AndreasFaust @Dupflo On closer inspection, I'm finding that the preview button does not update the URL unless you save the entity, which is intentional.

The preview button operates by sending your frontend app the data it needs in order to query the page/post from Strapi. So if you do not save the new slug value and your frontend app is going to query the page/post based on that slug, you need to save it before you preview it. In other words, you can only preview a page/post that has been saved in the database.

@AndreasFaust yes, this is why inside my PR, I used the updatedAt change to fire the modification. Then you are sure the updated slug has been updated inside the database

#62

What do you think ?

@Dupflo Ah, now I see how it is not updating. Very odd because it wasn't happening to me every time. Either way, we can fix it.

But in your PR it is quite difficult to see the actual new code you introduced because you included a lot of changes to quotes and spacing. Can you update it to only include the necessary code change you are proposing?

@mattmilburn Sorry ! Please recheck I updated it

Closing. This is resolved with PR #62 🎉