Flatten thread: fix behavior after replying
After replying to a thread, the new reply wasn't visible. This was due
to the fact that when the Community Console loaded the thread again, it
used the XHR property `responseText` to read the response instead of
`response`, but until now only `response` returned the modified response
instead of the original one.
Thus, this CL adds logic to also return the modified response (in text
form) when calling `responseText`.
Bug: twpowertools:156
Change-Id: If30112ca2827749a5d6677bfb9dfc790dabd9281
diff --git a/src/xhrInterceptor/XHRProxy.js b/src/xhrInterceptor/XHRProxy.js
index 288142a..2d6d03f 100644
--- a/src/xhrInterceptor/XHRProxy.js
+++ b/src/xhrInterceptor/XHRProxy.js
@@ -166,7 +166,6 @@
'onprogress',
'onreadystatechange',
'readyState',
- 'responseText',
'responseType',
'responseXML',
'status',
@@ -202,6 +201,13 @@
return this.xhr.response;
},
});
+ Object.defineProperty(window.XMLHttpRequest.prototype, 'responseText', {
+ get: function() {
+ if (!this.$responseIntercepted) return undefined;
+ if (this.$responseModified) return this.$newResponseText;
+ return this.xhr.responseText;
+ },
+ });
return this;
}