content icon indicating copy to clipboard operation
content copied to clipboard

Changing content in dev mode triggers execute-function of useAsyncData?

Open ahoiroman opened this issue 7 months ago • 5 comments

Environment

Version

3.5.1

Reproduction

https://github.com/ahoiroman/content-reproducer

Description

If content is edited and saved, the execute function is being called. In the reproducer you can see that, as the toast of the newsletter subscription is shown.

https://github.com/user-attachments/assets/d45dac53-e9fe-4cc1-b1ea-2455df625d33

Additional context

No response

Logs


ahoiroman avatar Jun 04 '25 08:06 ahoiroman

This is expected behavior, When you change the content in dev mode, the module asks Nuxt to reload the page data. By this Nuxt will recall data fetches. I suggest not writing logics like toast, etc, in the sync-data function.

farnabaz avatar Jun 09 '25 19:06 farnabaz

But when I am in a dashboard-like scenario, delete-procedures of resources will be triggered, even if I do not want that.

I would not call this expected behavior…? Especially not, when the data fetches are flagged with immediate: false

ahoiroman avatar Jun 10 '25 05:06 ahoiroman

Delete procedures and other api calls should be called at the top level. Delete should happen in an event and inside a function. Nuxt will only refresh top-level asyncs.

Please provide an example of the delete procedures.

farnabaz avatar Jun 10 '25 07:06 farnabaz

useAsyncData should not be called in a function, and I think we agree that I only should call the execute() function. And that's what I am doing. And the example does the same: https://github.com/ahoiroman/content-reproducer/blob/main/app/components/AppFooter.vue#L54

And if you stick to the example that is provided: This is a newsletter subscription, which is flagged with immediate: false. I would not expect a content change to perform POST, PUT, DELETE or PATCH calls or anything that is flagged with immediate: false.

To my understanding, posting/deleting/putting/patching data this way is totally fine. This is also shown by Alex Lichter (https://www.youtube.com/watch?v=njsGVmcWviY&t=213s), too.

ahoiroman avatar Jun 10 '25 08:06 ahoiroman

To my understanding, posting/deleting/putting/patching data this way is totally fine. This is also shown by Alex Lichter (youtube.com/watch?v=njsGVmcWviY&t=213s), too.

Watch what Alex suggests at the end of video. https://youtu.be/njsGVmcWviY?si=d8OprpUSkuMptmk0&t=588

I would not expect a content change to perform POST, PUT, DELETE or PATCH calls or anything that is flagged with immediate: false.

This is more like an issue with Nuxt itself than Nuxt Content module. Nuxt Content just asks Nuxt to refetch the data. If data is not fetched yet, Nuxt should respect that.

Also I highly recommend to not use Nuxt Async Composables for non 'GET` requests.

farnabaz avatar Jun 10 '25 09:06 farnabaz

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Aug 09 '25 09:08 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity.

github-actions[bot] avatar Sep 08 '25 09:09 github-actions[bot]