Skip to content

Conversation

@ematipico
Copy link
Member

@ematipico ematipico commented Sep 11, 2025

Changes

This PR does a further refactor of our internals. The main issue I was facing was the fact that I was trying to use the DevApp both in our internal dev server and the dev server spawned by external plugins such as Cloudflare.

This wasn't working and driving me nuts because DevApp uses a lot of Node.js APIs across the board. It was mental. So after thinking more about what @ascorbic said, we should try to use App instead, it actually made sense and it was the right approach. However, in dev, we handle a few things differently compared to production. For example, we handle 500 errors differently in dev.

So now, we have two apps:

  • AstroServerApp (which uses its own AstroServerPipeline)
  • DevApp (which uses its own DevPipeline)

AstroServerApp

It uses the code and business logic we currently use in our Astro server. The old DevPipeline has been renamed to AstroServerPipeline

DevApp

This new DevApp is mostly the same as App. They both use the same methods (such as render), they slightly differ in the match implementation, for example.

Since App and DevApp share the same logic, they are runtime-agnostic.

The new DevPipeline, for now, is a copy-paste of AppPipeline, however, we changed the logic of the function getComponentByRoute. In development, we don't have the compiled Astro files, so we need to dynamically import them e.g. import("path/to/file.astro). Eventually, in dev, our rollup plugin is triggered, and it should return the compiled code.

Testing

Minimal and react examples still work locally

Docs

@changeset-bot
Copy link

changeset-bot bot commented Sep 11, 2025

⚠️ No Changeset found

Latest commit: 4327fed

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) docs pr labels Sep 11, 2025
@ematipico ematipico changed the title refactor: use environments to load modules (#14191) refactor: dev app without settings and loader Sep 11, 2025
Copy link
Contributor

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little unclear why there needs to be two different sources of truth. Can it use the manifest settings in both cases?

@ematipico ematipico requested a review from ascorbic September 12, 2025 07:26
ascorbic
ascorbic previously approved these changes Sep 12, 2025
@ematipico ematipico changed the title refactor: dev app without settings and loader refactor: dedicated App for astro server and for external servers Sep 12, 2025
let info = this.getModuleInfo(result.id);
const astro = info && getAstroMetadata(info);
if (astro) {
if (astro && isRunnableDevEnvironment(environment)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not work with other envionrments?

Copy link
Member Author

@ematipico ematipico Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the question, but without this guard, the Cloudflare plugin emits errors

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant remove the guard in configureServer instead, so that it populates environment and can run in workerd too


import type { SharpImageServiceConfig } from '../assets/services/sharp.js';

export { createConsoleLogger, createNodeLogger } from '../core/config/index.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to export this from here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. It's not needed anymore

@ematipico ematipico dismissed ascorbic’s stale review September 12, 2025 15:40

The scope of the PR changed

@ematipico ematipico requested a review from ascorbic September 12, 2025 15:40
@ematipico ematipico merged commit a2e2965 into feat/environment-api Sep 15, 2025
7 of 20 checks passed
@ematipico ematipico deleted the env-api/settings-and-loader branch September 15, 2025 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs pr pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants