ebess / advanced-nova-media-library

A Laravel Nova field for displaying, creating, updating and ordering a Spatie Media Library model.
596 stars 297 forks source link

Check existence of computed value before display #416

Open gmooren opened 1 year ago

gmooren commented 1 year ago

There is an issue which became present in Laravel Nova v4 when using single media collections. When a record does not have a media collection as defined in the Files field, it will result in the following frontend error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'file_name')
    at Proxy.<anonymous> (media-lib-images-field:2:43292)
    at renderComponentRoot (runtime-core.esm-bundler.js:816:1)
    at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5701:1)
    at ReactiveEffect.run (reactivity.esm-bundler.js:178:1)
    at instance.update (runtime-core.esm-bundler.js:5814:1)
    at setupRenderEffect (runtime-core.esm-bundler.js:5822:1)
    at mountComponent (runtime-core.esm-bundler.js:5612:1)
    at processComponent (runtime-core.esm-bundler.js:5565:1)
    at patch (runtime-core.esm-bundler.js:5040:1)
    at mountChildren (runtime-core.esm-bundler.js:5284:1)

This is caused by the value attribute in the API response being an empty array. In Nova 4 the error will stop the table drawing process. In Nova 3 the same error is present but the table drawing just continues.