"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "unstable_after", {
    enumerable: true,
    get: function() {
        return unstable_after;
    }
});
const _requestasyncstorageexternal = require("../../client/components/request-async-storage.external");
const _workasyncstorageexternal = require("../../client/components/work-async-storage.external");
const _cacheasyncstorageexternal = require("../../server/app-render/cache-async-storage.external");
const _staticgenerationbailout = require("../../client/components/static-generation-bailout");
const _dynamicrendering = require("../app-render/dynamic-rendering");
function unstable_after(task) {
    const callingExpression = 'unstable_after';
    // TODO: This is not safe. afterContext should move to WorkStore.
    const requestStore = _requestasyncstorageexternal.requestAsyncStorage.getStore();
    if (!requestStore) {
        throw new Error(`\`${callingExpression}\` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context`);
    }
    const { afterContext } = requestStore;
    if (!afterContext) {
        throw new Error('`unstable_after()` must be explicitly enabled by setting `experimental.after: true` in your next.config.js.');
    }
    const workStore = _workasyncstorageexternal.workAsyncStorage.getStore();
    const cacheStore = _cacheasyncstorageexternal.cacheAsyncStorage.getStore();
    if (workStore) {
        if (workStore.forceStatic) {
            throw new _staticgenerationbailout.StaticGenBailoutError(`Route ${workStore.route} with \`dynamic = "force-static"\` couldn't be rendered statically because it used \`${callingExpression}\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`);
        } else {
            (0, _dynamicrendering.markCurrentScopeAsDynamic)(workStore, cacheStore, callingExpression);
        }
    }
    return afterContext.after(task);
}

//# sourceMappingURL=after.js.map