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

Context not available in astro:actions #12393

Open
1 task
mariusbolik opened this issue Nov 7, 2024 · 2 comments
Open
1 task

Context not available in astro:actions #12393

mariusbolik opened this issue Nov 7, 2024 · 2 comments
Labels
needs triage Issue needs to be triaged

Comments

@mariusbolik
Copy link

mariusbolik commented Nov 7, 2024

Astro Info

Astro                    v4.16.7
Node                     v20.15.0
System                   macOS (arm64)
Package Manager          bun
Output                   hybrid
Adapter                  @astrojs/cloudflare
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

A am using astro with the cloudflare adapter and output: 'hybrid'. I can't access methods from the ctx object without making the dev server crash. I receive the following error message:

AstroError [ActionNotFoundError]: The server received a request for an action named `url.searchParams.get` but could not find a match. If you renamed an action, check that you've updated your `actions/index` file and your calling code to match.
    at getAction (/Users/marius/Projects/Company/my-project/node_modules/astro/dist/actions/runtime/virtual/get-action.js:17:13)
    at async handleAction (astro:actions:68:18) {
  loc: undefined,
  title: 'Action not found.',
  hint: 'You can run `astro check` to detect type errors caused by mismatched action names.',
  frame: undefined,
  type: 'AstroError'
}

Same with ctx.cookies.get.

Here are the console logs of the ctx object:

ctx: {}
ctx.cookies: [Function: action] {
  queryString: '?_astroAction=cookies',
  toString: [Function: toString],
  '$$FORM_ACTION': [Function: $$FORM_ACTION],
  orThrow: [AsyncFunction: orThrow]
}
ctx.url: [Function: action] {
  queryString: '?_astroAction=url',
  toString: [Function: toString],
  '$$FORM_ACTION': [Function: $$FORM_ACTION],
  orThrow: [AsyncFunction: orThrow]
}

What's the expected result?

I would like to access the methods of the ctx object to read and write cookies.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-zqu2ga?file=src%2Fpages%2Findex.astro,src%2Factions%2Findex.ts&on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Nov 7, 2024
@Klerith
Copy link

Klerith commented Nov 7, 2024

I'm facing the same issue. When I try to get my cookies from action, I get the same object that doesn't contain the has, get and all the other methods from cookies.

cookies: [Function: action] {
    queryString: '?_astroAction=cookies',
    toString: [Function: toString],
    '$$FORM_ACTION': [Function: $$FORM_ACTION],
    orThrow: [AsyncFunction: orThrow]
  }

The code was working perfectly when the actions where in beta.

@mariusbolik
Copy link
Author

Good point @Klerith! I also remember that it used to work back when actions were an experimental feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants