Skip to content

Conversation

@ArmandPhilippot
Copy link
Member

@ArmandPhilippot ArmandPhilippot commented Oct 20, 2025

Description (required)

  • Adds some missing documented imports to the list: getActionContext and getActionPath.
  • Adds docs for ACTION_QUERY_PARAMS and actions.
  • Adds an astro:actions types section with docs for ActionAPIContext, ActionClient, ActionErrorCode, ActionReturnType, and SafeResult.
  • Adds a few more usage examples.
  • Updates most of the types either to fix them or to add links to the new headings
    • I also simplified some types. For example, I replaced ActionClient<any, any, any> with ActionClient because this is always <any, any, any> and it seems to be an implementation detail rather than something useful to the end-user. And because we now have docs for the types, I think it makes it easier to understand.
    • Fixes the defineAction() type: accept was missing while we were documenting it under input. Not sure if there was a reason for that, maybe we should use the same heading level as the others to avoid any confusion?
    • To avoid long/unreadable types and because we have a precedent, I used one Types: with a list instead of using an union.
  • Moves the codes list from code (in ActionError) to the new ActionErrorCode heading. And, actually, replace the outdated list with a description of the expected format and an external link.
  • Rewords some existing descriptions for consistency and to follow our API references guide... there are already a lot of changes so, while I'm here, I think a few more updates doesn't change much the work of translators (maybe reviewers tough, sorry!).
  • Removes Since when the version is the same as the module
  • Adds a few new links in the Actions guide (and fix full > subset).
Things we might want to consider
Not documented

Based on Florian's feedback, some of the available imports are not documented. I think it's fine (NWTWWHB) and they should be removed in v6.

See the list of undocumented imports

import {
  type Actions,
  type ActionAccept,
  type ActionHandler,
  type AstroActionContext,
  type SerializedActionResult,
  ACTION_ERROR_CODES,
  ActionInputError,
  appendForwardSlash,
  astroCalledServerError,
  callSafely,
  deserializeActionResult,
  formDataToObject,
  getActionQueryString,
  serializeActionResult,
} from "astro:actions";
Implementation links

There are a lot of changes, so I tried to keep track of the links to help you review the accuracy of the API blocks (type/since).
I haven't updated those list, so they include undocumented imports too.

Details of the "regular" imports:
Details of the type imports:

Related issues & labels (optional)

@ArmandPhilippot ArmandPhilippot added improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes) add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. labels Oct 20, 2025
@netlify
Copy link

netlify bot commented Oct 20, 2025

Deploy Preview for astro-docs-2 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c4165c4
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/68ff91e725cbf90008fd4f6c
😎 Deploy Preview https://deploy-preview-12596--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@astrobot-houston
Copy link
Contributor

astrobot-houston commented Oct 20, 2025

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
en/guides/actions.mdx Source changed, localizations will be marked as outdated.
en/reference/modules/astro-actions.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@ArmandPhilippot
Copy link
Member Author

ArmandPhilippot commented Oct 22, 2025

I think I've done all the changes I noticed here... Sorry for the Github diff: some content was already there but was moved.

I'm pinging @florian-lefebvre (no rush!) because I need a technical review to check the accuracy and if some things should be removed in v6, but anyone else is welcome to review this one!

I tried to keep a track of all the changes in the first post but there are a lot of changes so I'm not sure how readable/understandable it is. As explained in the issue, I noticed a lack of documentation for all the following imports:

import {
  ACTION_ERROR_CODES,
  ACTION_QUERY_PARAMS,
  ActionInputError,
  appendForwardSlash,
  astroCalledServerError,
  callSafely,
  deserializeActionResult,
  formDataToObject,
  getActionQueryString,
  serializeActionResult,
  type Actions,
  type ActionAPIContext,
  type ActionAccept,
  type ActionClient,
  type ActionErrorCode,
  type ActionHandler,
  type ActionReturnType,
  type AstroActionContext,
  type SafeResult,
  type SerializedActionResult,
} from "astro:actions";

So I would need a technical point of view for all of them, with some exceptions listed below:

  • Among them, I think some shouldn't be documented:
    • type Actions: I think it is only meant to type the actions export and shouldn't be used directly by the user?
    • astroCalledServerError: I don't see a use case for it... this sounds like an internal function to me.
    • callSafely: I don't see a use case for it... this sounds like an internal function to me.
    • ACTION_ERROR_CODES: I think the constant itself is not useful for users, only the ActionErrorCode type built from the constant?
    • ACTION_QUERY_PARAMS: same I think this is internal and this is only useful through utilities like getActionQueryString()
  • deserializeActionResult and serializeActionResult were already documented but as methods returned by getActionContext, not as imports from astro:actions. So I mostly moved around the docs here and duplicated the headings. I couldn't find a use case to prefer one over the other... so maybe this is something that should be updated? I mean either get them from getActionContext or as top level imports?

I added docs for:

  • appendForwardSlash but if we move things in v6, I think this could be a good candidate? This doesn't seem related to actions specifically and so it sounds a bit weird to document it here.
  • ActionInputError but I don't think there is a real use case for end-users because of isInputError

And because your issue was specifically about orThrow and queryString they are under ActionClient. Feel free to suggest a more accurate description!

I'm not quite sure about the organization. I documented some properties under their types but maybe it could be more useful under the related function... But, we can think about this later!

(If you need direct links to the implementation, they are listed under a details in Implementation links in the first post)

EDIT: I was also not sure about an use case for ActionReturnType, so I'm not confident about the description...

@ArmandPhilippot ArmandPhilippot marked this pull request as ready for review October 22, 2025 21:57
@florian-lefebvre
Copy link
Member

Thanks a lot! Before reviewing the content, let's agree on what not to document so we can remove them more easily in v6. For me:

  • ACTION_ERROR_CODES: do not document (internal)
  • ACTION_QUERY_PARAMS: document. This is actually useful for advanced cases (I've used it)
  • ActionInputError: do not document (internal)
  • appendForwardSlash: do not document (internal)
  • astroCalledServerError: do not document (internal)
  • callSafely: do not document (internal)
  • deserializeActionResult: do not document (probably better to have one source of truth with getActionContext()?)
  • formDataToObject: do not document (internal)
  • getActionQueryString: do not document (internal)
  • serializeActionResult: do not document (probably better to have one source of truth with getActionContext()?)
  • type Actions: do not document (we'll need to update the typegen in v6)
  • type ActionAPIContext: document
  • type ActionAccept: do not document (unless it's useful for something?)
  • type ActionClient: document (advanced but useful for generics)
  • type ActionErrorCode: document (and link to somewhere)
  • type ActionHandler: maybe not document? I feel like that can be explained as part of ActionClient
  • type ActionReturnType: document
  • type AstroActionContext: do not document (getActionContext() is the same)
  • type SafeResult: do not document (most people don't need it)
  • type SerializedActionResult: do not document (most people don't need it)

That's what I'm thinking but I may be wrong, happy to discuss further! Am I missing something?

@ArmandPhilippot
Copy link
Member Author

Thanks! Except maybe SafeResult (see below my reasoning), everything makes sense to me.

ACTION_QUERY_PARAMS: document. This is actually useful for advanced cases (I've used it)

Oh okay, I'll need your help to describe when this is useful then! 😅

type ActionAccept: do not document (unless it's useful for something?)

Probably not. It seems the accept property in defineAction is rather a static value.

type ActionHandler: maybe not document? I feel like that can be explained as part of ActionClient

I'm not sure I see the relationship with ActionClient. But I agree the type might not be useful, we can describe it directly in the handler() property of defineAction!

type AstroActionContext: do not document (getActionContext() is the same)

Makes sense! This is what I meant with "I documented some properties under their types but maybe it could be more useful under the related function...", so I agree this is probably not useful.

type SafeResult: do not document (most people don't need it)

While users might not need to use it directly, maybe this is still useful to describe the format? ie:

Type: { data: TOutput, error: undefined } | { data: undefined, error: ActionError }

Because many functions uses this and so we can link to a single place?

@florian-lefebvre
Copy link
Member

I'm not sure I see the relationship with ActionClient. But I agree the type might not be useful, we can describe it directly in the handler() property of defineAction!

Sorry yes that's what I meant!

Because many functions uses this and so we can link to a single place?

SGTM

</p>

`serializeActionResult()` will serialize an action result to JSON for persistence. This is required to properly handle non-JSON return values like `Map` or `Date` as well as the `ActionError` object.
Serializes an action result to JSON for persistence. This is required to properly handle non-JSON return values like `Map` or `Date` as well as the `ActionError` object.
Copy link
Member

@sarah11918 sarah11918 Oct 24, 2025

Choose a reason for hiding this comment

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

Such nice editing choices! 🙌

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Just left some comments below based on the text (and not yet looking at deploy preview to make sure all these code blocks render properly etc.).

There is some amazing writing here, and this is shaping up to be super high quality and helpful! Thank you both for the effort on these pages! 🙌

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
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.

LGTM thank you!

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Putting this stuff in the guide feels WAY better, I think! Thank you Armand!

Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
@ArmandPhilippot
Copy link
Member Author

Thanks @sarah11918 , I pushed a new commit with your two suggestions! I was a bit annoyed to have to repeat more or less the same information before, so I agree this makes more sense. 😄 I let you check the wording, but, yes, this looks better now!

Copy link
Member

@yanthomasdev yanthomasdev left a comment

Choose a reason for hiding this comment

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

LGTM! Amazing work here 🙌

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Love it! Thank you everyone! Let's Get That Money! 💰

@ArmandPhilippot
Copy link
Member Author

Thanks again everyone ❤️ , let's merge this! 🫡

@ArmandPhilippot ArmandPhilippot merged commit 3027821 into withastro:main Oct 27, 2025
10 checks passed
@ArmandPhilippot ArmandPhilippot deleted the feat/add-actions-api-references branch October 27, 2025 15:55
ArmandPhilippot added a commit to ArmandPhilippot/astro-docs that referenced this pull request Oct 28, 2025
getUserOrThrow: defineAction({
accept: 'form',
handler: async (_, { locals }) => {
if (locals.user?.name !== 'florian') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry that I am little very late to the party and that I criticize here, but is this a good example for "Not authorized". Personally, I find it a little bit confusing that the user is unauthorized, when they are not "florian". I mean, I love such easter eggs in the docs, but I'm not sure if they are maybe too confusing here...

Copy link
Member

Choose a reason for hiding this comment

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

Lol I completely missed that! I don't have strong opinions on this, I'll let others answer

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not an actions expert so I look at examples in the source code. 😅 I don't recall the exact example but I recall I adapt it a bit because the value seemed weird or something like that.

I guess we could update it with something like locals.user?.role !== 'admin' if you think this is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the delayed answer, but personally I would find the admin check more fitting. However, as I think I might be the only one that was confused by it, we might as well just leave it and if more people complain, we can update it... Would that be fine for you?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both work for me. But if you find this confusing, feel free to submit a PR to update the example! You may not be the only one, others might be hesitant to report this... So, as long as it's correct, an update can be helpful for others!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing Actions API in the reference

6 participants