{"record":{"id":"144137a3b8d5b363","repo":"OrchardCMS/OrchardCore","slug":"thenable-self-resolution","errorCode":null,"errorMessage":"Thenable self-resolution","messagePattern":"Thenable self-resolution","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.4.1/jquery.js","lineNumber":3562,"sourceCode":"\t\t\t\t\t\treturn function() {\n\t\t\t\t\t\t\tvar that = this,\n\t\t\t\t\t\t\t\targs = arguments,\n\t\t\t\t\t\t\t\tmightThrow = function() {\n\t\t\t\t\t\t\t\t\tvar returned, then;\n\n\t\t\t\t\t\t\t\t\t// Support: Promises/A+ section 2.3.3.3.3\n\t\t\t\t\t\t\t\t\t// https://promisesaplus.com/#point-59\n\t\t\t\t\t\t\t\t\t// Ignore double-resolution attempts\n\t\t\t\t\t\t\t\t\tif ( depth < maxDepth ) {\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturned = handler.apply( that, args );\n\n\t\t\t\t\t\t\t\t\t// Support: Promises/A+ section 2.3.1\n\t\t\t\t\t\t\t\t\t// https://promisesaplus.com/#point-48\n\t\t\t\t\t\t\t\t\tif ( returned === deferred.promise() ) {\n\t\t\t\t\t\t\t\t\t\tthrow new TypeError( \"Thenable self-resolution\" );\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// Support: Promises/A+ sections 2.3.3.1, 3.5\n\t\t\t\t\t\t\t\t\t// https://promisesaplus.com/#point-54\n\t\t\t\t\t\t\t\t\t// https://promisesaplus.com/#point-75\n\t\t\t\t\t\t\t\t\t// Retrieve `then` only once\n\t\t\t\t\t\t\t\t\tthen = returned &&\n\n\t\t\t\t\t\t\t\t\t\t// Support: Promises/A+ section 2.3.4\n\t\t\t\t\t\t\t\t\t\t// https://promisesaplus.com/#point-64\n\t\t\t\t\t\t\t\t\t\t// Only check objects and functions for thenability\n\t\t\t\t\t\t\t\t\t\t( typeof returned === \"object\" ||\n\t\t\t\t\t\t\t\t\t\t\ttypeof returned === \"function\" ) &&\n\t\t\t\t\t\t\t\t\t\treturned.then;\n\n\t\t\t\t\t\t\t\t\t// Handle a returned thenable\n\t\t\t\t\t\t\t\t\tif ( isFunction( then ) ) {\n","sourceCodeStart":3544,"sourceCodeEnd":3580,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.4.1/jquery.js#L3544-L3580","documentation":"jQuery's Deferred implementation throws this TypeError when a promise handler (an added done/fail/progress/then callback) returns the same deferred's own promise, which would make the promise resolve itself — a cycle forbidden by Promises/A+ (section 2.3.1). jQuery aborts to prevent infinite recursion.","triggerScenarios":"Inside a .then/.done handler on a jQuery deferred, returning the same deferred.promise() object, e.g. `d.then(function(){ return d.promise(); })`, or returning a thenable that is the promise itself.","commonSituations":"Chaining code that accidentally returns the original promise instead of a new one; reusing a deferred variable in a closure inside its own handler; refactored promise chains creating self-referential returns.","solutions":["Return a new promise/value from the handler, never the same deferred.promise()","Return a distinct thenable or plain value to chain properly","Restructure so the deferred used for resolution is created outside and not returned by its own handlers","Use native Promises, which reject cycles with 'Chaining cycle detected' instead"],"exampleFix":"// before\nvar d = $.Deferred();\nd.then(function () { return d.promise(); }); // TypeError: Thenable self-resolution\n// after\nvar d = $.Deferred();\nd.then(function (v) { return v; });","handlingStrategy":"type-guard","validationCode":"function returnsSelf(deferred, handler) { return handler && deferred.promise !== undefined; }","typeGuard":"function isSamePromise(returned, deferred) { return returned === deferred.promise(); }","tryCatchPattern":"try { d.then(handler); } catch (e) { if (e instanceof TypeError && e.message === 'Thenable self-resolution') { console.error('Handler returned its own promise'); } else { throw e; } }","preventionTips":["Never return deferred.promise() from a handler on that same deferred","Return plain values or fresh promises from .then handlers","Prefer native Promises over jQuery Deferreds for new code","Review refactored promise chains for closure variable self-reference"],"tags":["javascript","jquery","promise","deferred","circular-reference"],"backgroundTag":"invalid-state-transition","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}