diff --git a/javascript/elements/updates_for_element.js b/javascript/elements/updates_for_element.js index 768b45e9..acc009d0 100644 --- a/javascript/elements/updates_for_element.js +++ b/javascript/elements/updates_for_element.js @@ -120,7 +120,7 @@ export default class UpdatesForElement extends SubscribingElement { const response = await graciouslyFetch(url, { 'X-Cable-Ready': 'update' }) - this.html[url] = await response.text() + if (response) this.html[url] = await response.text() } }) ) @@ -254,7 +254,8 @@ class Block { ) const frameTemplate = document.createElement('template') - frameTemplate.innerHTML = await frameResponse.text() + if (frameResponse) + frameTemplate.innerHTML = await frameResponse.text() // recurse here to get all nested eager loaded frames await this.resolveTurboFrames(frameTemplate.content) diff --git a/javascript/utils.js b/javascript/utils.js index f636c282..39286c30 100644 --- a/javascript/utils.js +++ b/javascript/utils.js @@ -173,9 +173,15 @@ function safeObject (obj) { function safeStringOrArray (elem) { if (elem !== undefined && !Array.isArray(elem) && typeof elem !== 'string') - console.warn(`Operation expects an Array or a String, but got ${elem} (${typeof elem})`) + console.warn( + `Operation expects an Array or a String, but got ${elem} (${typeof elem})` + ) - return elem == null ? '' : Array.isArray(elem) ? Array.from(elem) : String(elem) + return elem == null + ? '' + : Array.isArray(elem) + ? Array.from(elem) + : String(elem) } function fragmentToString (fragment) { @@ -202,6 +208,7 @@ async function graciouslyFetch (url, additionalHeaders) { return response } catch (e) { console.error(`Could not fetch ${url}`) + return new Response('') } }