File field in navigation blueprint resets preview when sidepanel closes
Bug description
We have a file field to upload images in our navigation blueprint. When a user sets an image, saves the navigation item and reopens the navigation item side panel without reloading, the file field is no longer populated but defaults to the empty state.
After the tree is saved and the page reloaded the field is populated correctly but this behavior causes confusion to users.
How to reproduce
- Add a file field to a navigation blueprint
- Choose a file for a navigation item and save the item
- Click again on the same navigation item opening the side panel, without saving the tree or reloading first
- See that the file field is not showing your selected file as value
Happens both with newly uploaded files and existing files
Logs
Environment
$ php please support:details
Environment
Application Name: xxx
Laravel Version: 10.48.28
PHP Version: 8.2.24
Composer Version: 2.8.3
Environment: local
Debug Mode: ENABLED
URL: xxx.ddev.site
Maintenance Mode: OFF
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: redis
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file
Livewire
Livewire: v3.5.19
Statamic
Addons: 2
Sites: 6 (xxx - DE, xxx - EN, xxx - DK, and 3 more)
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.51.0 PRO
Statamic Addons
appswithlove/statamic-one-click-content-translation: 5.2.3
thoughtco/statamic-restrict-fields: 1.1.0
Installation
Existing Laravel app
Additional details
This issue already existed on previous versions, I just updated to verify it still affects the latest one
The "Files" fieldtype is only really intended to be used on forms and by addon developers. It only uploads the file, it doesn't actually handle storing it.
You should probably be using the Assets fieldtype instead.
Thank you for your response and sorry for the inaccuracy, but we are using a type: assets field for this. At least in the translated version of the CP the Fieldtype is called "Files" in the ui, thats why I referred to it that way.
-
handle: headerimage
field:
max_files: 1
container: images
type: assets
display: 'Headerbild'
localizable: false
Can this be reopened?
This looks like the same underlying issue as #10630. When you re-open a nav item after saving, the preview isn't displayed. It works as expected after refreshing the page.
The issue affects all fields in the nav blueprint not just asset fields :/
nav_test.yaml
tabs:
main:
display: Main
sections:
-
fields:
-
handle: assets_field
field:
container: assets
type: assets
display: 'Assets Field'
-
handle: replicator_field
field:
type: replicator
display: 'Replicator Field'
sets:
new_set_group:
display: 'New Set Group'
sets:
new_set:
display: 'New Set'
fields:
-
handle: text_field
field:
type: text
display: 'Text Field'
The issue is that when you close the PageEditor.vue, the entire VueX state gets destroyed. This results in losing all the meta data.
https://github.com/statamic/cms/blob/573d366fe749ea1f6b847f1aafcbe1883d04e255/resources/js/components/publish/Container.vue#L65-L69
This has been fixed in Statamic 6, which is due to be released ~Q3, with an alpha on its way in the next week or so. You can learn more about v6 on our blog.