Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): move actions inside core #13262

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ematipico
Copy link
Member

@ematipico ematipico commented Feb 17, 2025

Changes

This PR moves actions inside core. Actions are now part of the pipeline, and they are loaded in the same way the middleware is loaded:

  • using ModuleLoader in development
  • using its entry point after the first build
  • using its moduleId when build for SSR

The internal virtual module of the actions is in charge of emitting a stub of the actions in case the user doesn't have any.

The injections of the actions during development is done inside the route.ts. I decided to do it there because I wanted to assume that the actions must be already loaded when creating the RenderContext, which is our agnostic runtime renderer. Because fo that, the Pipeline class also exposes a method called setActions.

Testing

Current tests and functionality should stay the same. The Actions middleware was already set to be the last one, which is the same as we just moved inside the lastNext callback we have in core.

Docs

N/A

Copy link

changeset-bot bot commented Feb 17, 2025

🦋 Changeset detected

Latest commit: 126ec8a

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Feb 17, 2025
@ematipico ematipico force-pushed the refactor/astro-actions branch from fd88009 to e285d9e Compare February 17, 2025 13:57
Copy link
Member

@florian-lefebvre florian-lefebvre left a comment

Choose a reason for hiding this comment

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

Although this is a refactor, maybe should we have a changeset to be safe in case people face issues

@ematipico ematipico force-pushed the refactor/astro-actions branch 2 times, most recently from b9ef104 to bd84a49 Compare February 17, 2025 14:02
Copy link

codspeed-hq bot commented Feb 17, 2025

CodSpeed Performance Report

Merging #13262 will not alter performance

Comparing refactor/astro-actions (b003bac) with main (2e1321e)

Summary

✅ 6 untouched benchmarks

@ematipico ematipico marked this pull request as draft February 17, 2025 15:44
@ematipico
Copy link
Member Author

Turns out it is not as simple as that, it requires a full refactor of the architecture. I'll see to that

@ematipico ematipico force-pushed the refactor/astro-actions branch 2 times, most recently from 64e2187 to c2042d2 Compare February 18, 2025 15:19
@ematipico
Copy link
Member Author

I checked the e2e test that failed, and the issue isn't much clear. The db package fails to run the seed file, however it doesn't happen when I run the dev server for the fixture.

Also, when running the fixture locally, the likes action (the action) works as expected, but the query doesn't return the expected data. This doesn't happen for the comments action.

As for now, I commented on them.

@ematipico ematipico force-pushed the refactor/astro-actions branch from f47d495 to 0cf031e Compare February 20, 2025 12:55
@@ -17,7 +18,7 @@ export function PostComment({
<form
method="POST"
data-testid="client"
action={actions.blog.comment}
action={actions.blog.comment.toString()}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that if this is required, it's a user-side bug. Understand if this is just a debug in-progress

Copy link
Member Author

Choose a reason for hiding this comment

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

That's intentional. For some reason, the toString() isn't called anymore. Has something changed in the TSX compiler? I bet that if we use a template literal, the toString() function is called, however... like this, toString() isn't automatically called, so I am afraid the transformation is doing something fishy

@@ -192,6 +194,15 @@ export class RenderContext {
}
let response: Response;

if (!ctx.isPrerendered) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Choose a reason for hiding this comment

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

Amazing. Thank you guys.

@bholmesdev bholmesdev added the pr preview This PR has a preview release label Feb 24, 2025
Copy link

pkg-pr-new bot commented Feb 24, 2025

astro

npm i https://pkg.pr.new/astro@13262

@astrojs/cloudflare

npm i https://pkg.pr.new/@astrojs/cloudflare@13262

@astrojs/netlify

npm i https://pkg.pr.new/@astrojs/netlify@13262

@astrojs/node

npm i https://pkg.pr.new/@astrojs/node@13262

@astrojs/vercel

npm i https://pkg.pr.new/@astrojs/vercel@13262

commit: 126ec8a

@ematipico ematipico force-pushed the refactor/astro-actions branch from 0cf031e to 126ec8a Compare February 25, 2025 14:57
@ematipico ematipico added pr preview This PR has a preview release and removed pr preview This PR has a preview release labels Feb 25, 2025
@ematipico ematipico changed the title refactor(core): remove middleware from actions refactor(core): move actions inside core Feb 25, 2025
@ematipico
Copy link
Member Author

@JacobNWolf, can you please use the latest preview release and see if that fixes your issue?

@ematipico ematipico marked this pull request as ready for review February 25, 2025 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pr preview This PR has a preview release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants