{"record":{"id":"7a5c8fc77b0a11d4","repo":"OrchardCMS/OrchardCore","slug":"thenable-self-resolution-7a5c8f","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.5.1/jquery.slim.js","lineNumber":3767,"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":3749,"sourceCodeEnd":3785,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.5.1/jquery.slim.js#L3749-L3785","documentation":"Same Promises/A+ self-resolution guard as the full build: jQuery's Deferred (present in the slim build) throws this TypeError when a resolution handler returns the very promise being resolved, which would create an unresolvable cycle.","triggerScenarios":"A .then()/.pipe()/.state()-chain handler returning the same deferred.promise(); resolving a deferred with its own promise object.","commonSituations":"Retry/recursion wrappers accidentally returning the outer deferred; shared module-level deferreds reused across calls; callback-to-promise refactors that return the same promise from within its own then handler.","solutions":["Find the handler in the stack that returns the promise and return a new Deferred's promise, a plain value, or another (different) promise instead.","Add a guard before resolving: throw if the candidate value === the deferred's own promise.","Refactor shared deferreds so each logical operation creates its own Deferred instance.","Prefer native Promises or $.when over manually returning deferred.promise() inside its own chains."],"exampleFix":"// before\npromise.then(function loop() {\n  return promise; // TypeError: Thenable self-resolution\n});\n// after\npromise.then(function (v) {\n  return retry(v); // return a NEW promise\n});","handlingStrategy":"type-guard","validationCode":"function resolveSafely(d, v) {\n  if (v && v.then && v === d.promise()) { return $.Deferred().reject(new TypeError('self-resolution blocked')); }\n  d.resolve(v);\n}","typeGuard":"function isThenable(v) { return !!v && (typeof v === 'object' || typeof v === 'function') && typeof v.then === 'function'; }\nfunction isOwnPromise(d, v) { return isThenable(v) && v === d.promise(); }","tryCatchPattern":"$.when(promise).then(h).fail(function (e) { if (e && e.message === 'Thenable self-resolution') { recoverChain(); } });","preventionTips":["Return new promises from then handlers, never the chained promise itself.","Avoid shared global Deferreds; scope them per call.","Add invariant checks before resolve() in wrapper utilities.","Consider native Promise implementations during refactors."],"tags":["jquery","slim","promise","deferred"],"backgroundTag":"internal-invariant-violation","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"}