Cannot read property 'jqXHR' of undefined

AI-generated summary

Cannot read property ‘jqXHR’ of undefined

A “Cannot read property ‘jqXHR’ of undefined” error occurred when trying to save a post edit in Discourse. tophee initially reported the issue, describing a scenario where the saving wheel kept spinning, and the error message appeared after attempting to resave the edit.

tanius was able to reproduce the issue on a different post, noting that it seemed to be an edge case. They found that the error was not related to the posted content, but rather to the saving process itself. tanius also shared error log entries, which appeared to be unrelated to the error message.

Stefan_Brighiu_M reported a similar error when adding a validator to the Post class in a plugin. The error disappeared after refreshing the page and restarting the server instance.

@techAPJ was unable to reproduce the issue on the latest Discourse version. codinghorror suggested using the Chrome network tab to simulate an unreliable network to aid in reproducing the issue.

The issue is not persisting, but users are seeking a more reliable way to handle failed post-saving due to network errors, including a way to resubmit the request without losing content.

I just did a minor change in the privacy policy but when I submitted the edit, it would not complete saving (the saving wheel kept spinning and spinning). While I was waiting, I went to the TOS (in a new browser tab) to do a change there too. After saving that edit without problems, I went back to the privacy policy, but the wheel was still spinning. So I went ahead and tried to edit the post again (in the same browser tab). Ironically, I found that the change was already made but I wasn’t sure whether it was really saved or whether I was just looking at the same unsaved editor content. So I clicked save to make sure it is saved. That’s when this error popped up.

Can you repro this @techapj?

I am unable to repro this error on latest Discourse version.

For what it’s worth, I just had this same issue with a recent Discourse version (commit c10941b, basically the stable branch from 2019-02-17, not a release).

I was able to reproduce it a few times, but then not anymore, and it’s the first time ever that I had this issue. So very much an edge case …

What happened:

  1. I did a major update to a complex wiki post (which is a Discourse manual we wrote for our purposes).

  2. As experienced by the OP, Discourse would not complete saving (the saving wheel kept spinning and spinning). I eventually cancelled the process.

  3. I tried to make the very same edit again, and this error popped up:

    TypeError: Cannot read property ‘jqXHR’ of undefined

    That was reproducible for several further attempts to make the same edit in this post.

  4. I tried to make an edit to a different post, and that went without problems. I tried to post the same edit that failed for the manual wiki as edit to the different post, and that worked without problems, too (so it does not seem to be connected to the posted content).

  5. I tried a small (few words) edit to the manual wiki where the original edit failed. That worked, but it took a long time (about two minutes).

  6. I tried the failed edit again on the manual wiki, and this time it worked. And all subsequent edits worked, too.

I found the following error log entries for the time and post where this issue happened:

(Edit: upon further inspection, that error in the logs seems rather unrelated as the log shows it also in multiple other cases, which did not involve the “TypeError: Cannot read property ‘jqXHR’ of undefined” error message on the client side. But I saved the JS file where the error happened, if somebody wants to look at it.)

Message (5 copies reported)
Uncaught Error: Not Found
Url: https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js
Line: 14
Column: 25883
Window Location: https://edgeryders.eu/t/discourse-user-manual-for-edgeryders-eu/6463/1
Backtrace
Error: Not Found
    at s (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:14:26084)
    at o (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:14:25941)
    at i (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:14:25836)
    at Object.trigger (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:17:26248)
    at https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:17:28250
    at e.invoke (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:9:3979)
    at e.flush (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:9:2902)
    at e.flush (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:9:4992)
    at e._end (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:9:9818)
    at e.end (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:9:6320)
    at e._run (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:9:10333)
    at e.run (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:9:6965)
    at a (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:4:29639)
    at Object.r.error (https://edgeryders.eu/assets/application-b7e1701c68247f1198a83883a70ad5264302ef5fd43e37b09ce6d0125baa133a.js:7:26015)
    at u (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:2:6854)
    at Object.fireWith [as rejectWith] (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:2:7603)
    at n (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:3:10363)
    at XMLHttpRequest.<anonymous> (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06ed7d3.js:3:15221)

Env
    hostname	server.edgeryders.eu
    process_id	27682
    application_version	2.2.1
    HTTP_HOST	edgeryders.eu
    REQUEST_URI	/logs/report_js_error
    REQUEST_METHOD	POST
    HTTP_USER_AGENT	Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/73.0.3683.75 Chrome/73.0.3683.75 Safari/537.36
    HTTP_ACCEPT	*/*
    HTTP_REFERER	https://edgeryders.eu/t/discourse-user-manual-for-edgeryders-eu/6463/1
    params
        message	Uncaught Error: Not Found Url: https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb3736
        url	https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58a4a8a83bcee2d99174547b01c06
        line	14
        column	25883
        window_location	https://edgeryders.eu/t/discourse-user-manual-for-edgeryders-eu/6463/1
        stacktrace	Error: Not Found at s (https://edgeryders.eu/assets/ember_jquery-cf9339810550f9c92505dfbb37362c58

Sorry @tanius Akismet thought your post was spam for some reason and deleted it, I just went ahead and undeleted it.

@techAPJ can you re-test given this info?

이 문제가 계속되고 있나요?

“Cannot read field jqXHR” 오류는 실패한 AJAX 호출 주위의 사용자 정의 오류 처리 코드에서 발생합니다.

아니요, 영구적으로 해결된 것은 아닙니다… 지난 1년 동안 그 오류를 확인하지는 못했습니다. 하지만 애초에 매우 드문 엣지 케이스였고 명확하게 재현되지도 않았기 때문에, 이를 오류가 없다는 증거로 받아들이지는 않겠습니다…

참고로, 게시글 저장 실패와 관련하여 개선할 수 있는 부분이 하나 더 있습니다. 바로 네트워크 오류로 인해 게시글이나 수정 사항을 저장하지 못했을 때, 시스템이 이를 알려주기까지 매우 긴 시간이 소요된다는 점입니다. 해당 요청을 다시 제출할 수 있는 방법이 없습니다. “취소” 버튼은 도움이 되지 않습니다. 이 버튼을 누르면 작성한 게시글이나 수정 내용이 사라지기 때문입니다.

무엇을 하려면 재현이 필요합니다. Chrome의 네트워크 탭을 조작해서 인위적으로 불안정한 네트워크로 전환해 보셨나요? 그러면 재현이 가능할지도 모르겠네요?

다음 작업을 수행하던 중 나에게 이 오류가 발생했습니다.
모든 작업은 플러그인 내에서 수행되었습니다.

Post 클래스에 Validator를 추가하고 있었습니다… 내용은 중요하지 않지만, 답변을 위해 아래에 포함합니다.

frozen_string_literal: true

class MainPostValidator < ActiveModel::Validator
def validate(record)
puts ‘TTTTT’
p record

raw = record.raw

unless raw.present?
  post.errors.add :base, 'This record is invalid'
end

end

private
def some_complex_logic
# …
end
end

새로운 변경 사항과 함께 서버를 실행하기 전에, 게시글 편집 화면이 열린 상태로 웹사이트를 열어 두었습니다. 변경 사항 저장이 내 Validator를 트리거하는지 확인하려고 준비 중이었죠.

서버를 재시작했지만 페이지를 새로고장하지 않았습니다! 게시글의 변경 사항 저장을 누르자 그 오류가 보였습니다. 페이지를 새로고장하자 오류가 사라졌고, 아마도 서버 인스턴스도 재시작한 것 같습니다.

이 모든 작업은 로컬 개발 환경에서 이루어졌습니다.

도움이 되길 바랍니다 :slight_smile:

Validator는 새로운 파일에 선언되었고, Validator를 적용하기 위한 Post의 추가 코드도 새로운 파일에 있었습니다.

require_dependency 'post' Post.class_eval { include ActiveModel::Validations validates_with MainPostValidator }