{"record":{"id":"77564de76ed93468","repo":"OrchardCMS/OrchardCore","slug":"thenable-self-resolution-jquery-slim","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.slim.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.slim.js#L3544-L3580","documentation":"The slim build has the same Deferred implementation: it throws TypeError('Thenable self-resolution') when a handler attached to a deferred returns that deferred's own promise, which would violate Promises/A+ 2.3.1 by making a promise resolve to itself.","triggerScenarios":"Returning the same deferred.promise() from within a .then/.done/.fail handler on that deferred, e.g. `var d = $.Deferred(); d.then(() => d.promise());`.","commonSituations":"Promise chains refactored so a handler returns the closure variable holding the original deferred; helper functions that return the deferred they are chained on; accidental reuse of a single deferred across chained calls.","solutions":["Never return deferred.promise() from a handler attached to that same deferred; return a new $.Deferred().promise() or a plain value","Return a different thenable or value to continue the chain","Flatten the chain using .then returning plain results","Migrate to native Promises which report cycles via rejection instead"],"exampleFix":"// before\nvar d = $.Deferred();\nd.then(function () { return d.promise(); });\n// after\nvar d = $.Deferred();\nd.then(function (v) { return $.Deferred().resolve(v).promise(); });","handlingStrategy":"type-guard","validationCode":"null","typeGuard":"function isSelfReturn(returned, deferred) { return returned != null && typeof returned.then === 'function' && returned === deferred.promise(); }","tryCatchPattern":"try { d.then(handler); } catch (e) { if (e instanceof TypeError && e.message === 'Thenable self-resolution') { console.error('Deferred handler returned its own promise'); } else { throw e; } }","preventionTips":["Never return the same deferred's promise from its own handler","Return plain values or newly created promises in .then callbacks","Use native Promises for new chains to get clearer cycle detection","Audit shared deferred variables across chained handlers"],"tags":["javascript","jquery","promise","deferred","slim","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"}