From 2405fc66f6d911ad738deb36cfe032ec6024d325 Mon Sep 17 00:00:00 2001 From: Sergio Alcaraz Date: Sun, 24 May 2026 21:10:10 -0300 Subject: [PATCH] Fix TypeError: Cannot read properties of null Turbo expects that when there are errors in validations, for example, it should respond with status 422, which causes the iframe to disappear from the DOM, so the null error occurs in subsequent requests. --- webroot/js/inject-iframe.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webroot/js/inject-iframe.js b/webroot/js/inject-iframe.js index 357fe0d6..ab77bc1a 100644 --- a/webroot/js/inject-iframe.js +++ b/webroot/js/inject-iframe.js @@ -77,7 +77,7 @@ if (elem) { url: this._arguments && this._arguments[1], type: this.getResponseHeader('Content-Type'), }; - iframe.contentWindow.postMessage(`ajax-completed$$${JSON.stringify(params)}`, window.location.origin); + iframe.contentWindow?.postMessage(`ajax-completed$$${JSON.stringify(params)}`, window.location.origin); } if (original) { return original.apply(this, [].slice.call(arguments)); @@ -124,7 +124,7 @@ if (elem) { url, type: response.headers.get('Content-Type'), }; - iframe.contentWindow.postMessage(`ajax-completed$$${JSON.stringify(params)}`, window.location.origin); + iframe.contentWindow?.postMessage(`ajax-completed$$${JSON.stringify(params)}`, window.location.origin); } return response; } catch (error) { @@ -138,7 +138,7 @@ if (elem) { type: null, error: error.message, }; - iframe.contentWindow.postMessage(`ajax-completed$$${JSON.stringify(params)}`, window.location.origin); + iframe.contentWindow?.postMessage(`ajax-completed$$${JSON.stringify(params)}`, window.location.origin); throw error; } };