spatie / statamic-responsive-images

Responsive images for Statamic 3
MIT License
99 stars 29 forks source link

Fix ResponsiveFieldtype erroring out in Replicator sets #192

Closed ncla closed 1 year ago

ncla commented 1 year ago

Addresses #186.

The bug is that if ResponsiveFieldtype is within a replicator set, it gets wonky as it utilizes PublishContainer (and PublishFields) to create it's Fiedltype based on already existing Statamic core Fieldtypes.

PublishContainer registers a new publish store in Vuex. So if I have three replicator sets, theres three publish stores because there are three ResponsiveFieldtypes.

image

Now if I were to delete the middle set, now there are two sets with that responsive field, but the 2nd one errors out as it is now referencing publish vuex store that does not exist (as far as I understood). The Vuex store looks like this now.

image

Please do not ask me why ResponsiveFieldtype has been coded like this - I do not know the answer. It may be possible to get away with just PublishFields component but I am not sure and have not tried yet fully.

I tried a cheesy solution of passing different name prop to PublishContainer in ResponsiveFieldtype, from computed property that has something like this.$props.handle + '.' + uniqid() (basically to have unique random ID). See image below of how Vuex store looks with this. This seems to have solved the issue I think, as deleting the middle set no longer produces the error in the issue. But this does not sit right with me atm.

image