Repository: withastro/astro
File: packages/astro/src/core/render-context.ts (TypeScript)

Code before:
					this.request = payload;
				} else {
					this.request = copyRequest(
						newUrl,
						this.request,
						// need to send the flag of the previous routeData
						routeData.prerender,
						this.pipeline.logger,
						this.routeData.route,
					);
				}
				this.isRewriting = true;
				this.url = new URL(this.request.url);
				this.cookies = new AstroCookies(this.request);
				this.params = getParams(routeData, pathname);
				this.pathname = pathname;
				this.status = 200;
			}
			let response: Response;

			if (!ctx.isPrerendered) {
				const { action, setActionResult, serializeActionResult } = getActionContext(ctx);

				if (action?.calledFrom === 'form') {
					const actionResult = await action.handler();
					setActionResult(action.name, serializeActionResult(actionResult));
				}
			}

			switch (this.routeData.type) {
				case 'endpoint': {
					response = await renderEndpoint(
						componentInstance as any,
						ctx,
						this.routeData.prerender,
						logger,
					);
					break;
				}
				case 'redirect':
					return renderRedirect(this);
				case 'page': {
					const result = await this.createResult(componentInstance!, actionApiContext);
					try {
						response = await renderPage(
							result,
							componentInstance?.default as any,
							props,
							slots,
							streaming,
							this.routeData,

Review comment (suggestion):
Nice, this looks like the fix we needed.

And I'll add some context from @JacobNWolf 's issue to make sure we test it: Actions were being bundled into edge middleware, when they should only be bundled into your server runtime. It looks like this moves the _functionality_ into the server runtime, but I wanna make sure we make a test project (ideally a fixture) that confirms actions aren't bundled into middleware by accident still.

Code after:
				}

				this.routeData = routeData;
				componentInstance = newComponent;
				if (payload instanceof Request) {
					this.request = payload;
				} else {
					this.request = copyRequest(
						newUrl,
						this.request,
						// need to send the flag of the previous routeData
						routeData.prerender,
						this.pipeline.logger,
						this.routeData.route,
					);
				}
				this.isRewriting = true;
				this.url = new URL(this.request.url);
				this.cookies = new AstroCookies(this.request);
				this.params = getParams(routeData, pathname);
				this.pathname = pathname;
				this.status = 200;
			}
			let response: Response;

			if (!ctx.isPrerendered) {
				const { action, setActionResult, serializeActionResult } = getActionContext(ctx);

				if (action?.calledFrom === 'form') {
					const actionResult = await action.handler();
					setActionResult(action.name, serializeActionResult(actionResult));
				}
			}

			switch (this.routeData.type) {
				case 'endpoint': {
					response = await renderEndpoint(
						componentInstance as any,
						ctx,
						this.routeData.prerender,
						logger,
					);
					break;
				}
				case 'redirect':
					return renderRedirect(this);
				case 'page': {
					const result = await this.createResult(componentInstance!, actionApiContext);
					try {
						response = await renderPage(
							result,