{"record":{"id":"c1bee88315eedc81","repo":"OrchardCMS/OrchardCore","slug":"thenable-self-resolution-c1bee8","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.6.0/jquery.slim.js","lineNumber":3771,"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":3753,"sourceCodeEnd":3789,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.6.0/jquery.slim.js#L3753-L3789","documentation":"Same Promises/A+ guard as in jquery.js, present in jquery.slim.js: a jQuery Deferred throws TypeError \"Thenable self-resolution\" when a promise is resolved (or a .then handler returns) with the promise object itself. Self-resolution would loop forever, so the spec mandates rejection with this TypeError.","triggerScenarios":"deferred.resolve(deferred.promise()); returning the same promise from inside its own .then() handler; a function that both creates a deferred and resolves it with its own promise (e.g. in recursive or cached-promise patterns).","commonSituations":"Memoized async functions that cache the promise and pass it back as the resolution value; refactors that accidentally alias the outer promise; chains where a handler intended to return data but returned the chain itself.","solutions":["Resolve with the concrete value or a distinct promise, never the same promise/deferred object.","Audit .then() callbacks for returns of the outer promise variable; return the payload or a new promise instead.","Restructure recursive promise code so each recursion creates a fresh deferred, or convert to async/await.","Guard with a check: if (value === myPromise) throw/handle before resolving."],"exampleFix":"// before\npromise.then(function () {\n  return promise; // self-resolution\n});\n\n// after\npromise.then(function (result) {\n  return process(result); // return a value or a different promise\n});","handlingStrategy":"type-guard","validationCode":"function resolveSafe(deferred, value) {\n  if (value && (value === deferred || value === deferred.promise())) return; // skip self-resolution\n  deferred.resolve(value);\n}","typeGuard":"function isSamePromise(p, v) { return v === p; }","tryCatchPattern":"promise.catch(function (err) {\n  if (err instanceof TypeError && err.message === 'Thenable self-resolution') {\n    // break the cycle: re-run with corrected resolution value\n  } else { throw err; }\n});","preventionTips":["Never resolve a deferred with its own promise object.","Return values or other promises — not the current chain — from .then() handlers.","In memoized async helpers, guard cached promises against being passed as resolution values.","Prefer async/await for recursive flows to surface cycles as clearer errors."],"tags":["jquery","promise","deferred","async"],"backgroundTag":"promise-self-resolution","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"}