apostrophecms / apostrophe

A full-featured, open-source content management framework built with Node.js that empowers organizations by combining in-context editing and headless architecture in a full-stack JS environment.
https://apostrophecms.com
Other
4.36k stars 590 forks source link

Singleton field in schema of apostrophe-pieces-widgets fails to retrieve image after saving widget #2704

Open perusoa opened 3 years ago

perusoa commented 3 years ago

To Reproduce

Step by step instructions to reproduce the behavior:

  1. Add a singleton field to your pieces-widgets schema and set it to be an apostrophe-images type
  2. In the widget template, setup the code to grab the image and then render out the attachment url
  3. Inside of your widget, add the image to your field you added earlier
  4. Save the widget
  5. Then you will see the red missing image icon error in the template
  6. Wait for the "Saved!" message in the bottom left
  7. Refresh the page, you will now see the image rendering completely normal
  8. Go edit the widget again, and either just re-save it, or change the image and save the widget again
  9. See error again

Expected behavior

I would expect the image to just update or render normally after each save of the widget, not just on page load.

Describe the bug

With apostrophe-pieces-widgets where if I add an apostrophe-images singleton field to the widget schema, then if I save the widget, I get the missing image error icon. But if I refresh the page, the image shows completely fine. Then if I go into the widget and re-save/make any changes and save the widget, the missing image error occurs again.

Details

Version of Node.js: v12.19.0

Server Operating System: MacOS Catalina V 10.15.7

abea commented 3 years ago

Without reproducing this yet, it seems pretty likely that this is from the base pieces widget overriding the load function from apostrophe-widgets without the joining/area-population. I don't think it would be a BC break to have the pieces widget use the super pattern instead of overriding (unless it actually breaks stuff).

boutell commented 3 years ago

I believe that would actually cause some issues, in that it would load the main join with selected items regardless of whether that type of population was chosen, and that would impact the performance wins in the standard load method for this widget. This would take more work to get right, in other words.