OrchardCMS/OrchardCore · error · TypeError

Thenable self-resolution

Error message

Thenable self-resolution

What it means

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.

Solutions

  1. Never return deferred.promise() from a handler attached to that same deferred; return a new $.Deferred().promise() or a plain value
  2. Return a different thenable or value to continue the chain
  3. Flatten the chain using .then returning plain results
  4. Migrate to native Promises which report cycles via rejection instead

Example fix

// before
var d = $.Deferred();
d.then(function () { return d.promise(); });
// after
var d = $.Deferred();
d.then(function (v) { return $.Deferred().resolve(v).promise(); });
Defensive patterns

Strategy: type-guard

Validate before calling

null

Type guard

function isSelfReturn(returned, deferred) { return returned != null && typeof returned.then === 'function' && returned === deferred.promise(); }

Try / catch

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; } }

Prevention

When it happens

Trigger: Returning the same deferred.promise() from within a .then/.done/.fail handler on that deferred, e.g. `var d = $.Deferred(); d.then(() => d.promise());`.

Common situations: 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.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/77564de76ed93468. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.4.1/jquery.slim.js:3562

						return function() {
							var that = this,
								args = arguments,
								mightThrow = function() {
									var returned, then;

									// Support: Promises/A+ section 2.3.3.3.3
									// https://promisesaplus.com/#point-59
									// Ignore double-resolution attempts
									if ( depth < maxDepth ) {
										return;
									}

									returned = handler.apply( that, args );

									// Support: Promises/A+ section 2.3.1
									// https://promisesaplus.com/#point-48
									if ( returned === deferred.promise() ) {
										throw new TypeError( "Thenable self-resolution" );
									}

									// Support: Promises/A+ sections 2.3.3.1, 3.5
									// https://promisesaplus.com/#point-54
									// https://promisesaplus.com/#point-75
									// Retrieve `then` only once
									then = returned &&

										// Support: Promises/A+ section 2.3.4
										// https://promisesaplus.com/#point-64
										// Only check objects and functions for thenability
										( typeof returned === "object" ||
											typeof returned === "function" ) &&
										returned.then;

									// Handle a returned thenable
									if ( isFunction( then ) ) {

View on GitHub (pinned to 4306c0717f)