fix(test): preserve invariant config failures
This commit is contained in:
@@ -75,7 +75,9 @@ RegistryService.prototype.plugin = function(plugin: Plugin, config?: unknown, ge
|
||||
if (hasBarrierOwner(host, this.ctx)) {
|
||||
return originalPlugin.call(this, plugin, config, getOuterStack)
|
||||
}
|
||||
if (callback === undefined) return originalPlugin.call(this, plugin, config, getOuterStack)
|
||||
if (callback === undefined) {
|
||||
return originalPlugin.call(this, plugin, config, getOuterStack)
|
||||
}
|
||||
|
||||
const fiber = originalPlugin.call(
|
||||
this,
|
||||
@@ -83,8 +85,9 @@ RegistryService.prototype.plugin = function(plugin: Plugin, config?: unknown, ge
|
||||
config,
|
||||
getOuterStack,
|
||||
)
|
||||
const initiallyPending = fiber.ctx.fiber.state === FiberState.PENDING
|
||||
host.barrierOwners.add(fiber.ctx.fiber)
|
||||
return joinInvariantStartup(fiber, host.ready)
|
||||
return joinInvariantStartup(fiber, host.ready, initiallyPending)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,8 +207,25 @@ function withInvariantReadiness(plugin: Plugin, callback: PluginCallback): Plugi
|
||||
}
|
||||
}
|
||||
|
||||
function joinInvariantStartup(fiber: PluginFiber, invariantReady: Promise<void>): PluginFiber {
|
||||
const readiness = invariantReady.then(() => fiber.await())
|
||||
function joinInvariantStartup(
|
||||
fiber: PluginFiber,
|
||||
invariantReady: Promise<void>,
|
||||
disposeInitialFailure = false,
|
||||
): PluginFiber {
|
||||
// RegistryService returns a thenable wrapper whose context still points to
|
||||
// the raw Fiber. Calling inherited await() on the wrapper would return and
|
||||
// assimilate that thenable, accidentally following later plugin startup.
|
||||
const rawFiber = fiber.ctx.fiber
|
||||
const initialized = disposeInitialFailure
|
||||
? rawFiber.await().catch(async (error: unknown) => {
|
||||
// Config validation is the only failure recorded while a gated fiber
|
||||
// is initially PENDING. Dispose it even if queued readiness publication
|
||||
// changes its state before this rejection handler runs.
|
||||
await rawFiber.dispose()
|
||||
throw error
|
||||
})
|
||||
: Promise.resolve()
|
||||
const readiness = initialized.then(() => invariantReady).then(() => rawFiber.await())
|
||||
const joined = Object.create(fiber) as PluginFiber
|
||||
joined.then = readiness.then.bind(readiness)
|
||||
return joined
|
||||
|
||||
Reference in New Issue
Block a user