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

[🐞] onPost not working properly #6112

Open
barel-mishal opened this issue Apr 10, 2024 · 7 comments
Open

[🐞] onPost not working properly #6112

barel-mishal opened this issue Apr 10, 2024 · 7 comments
Assignees
Labels
STATUS-2: team is working on this Scheduled for work by the core team TYPE: bug Something isn't working WAITING FOR: team Waiting for one of the core team members to review and reply

Comments

@barel-mishal
Copy link
Contributor

barel-mishal commented Apr 10, 2024

Which component is affected?

Qwik Runtime

Describe the bug

I am doing onPost and expect it too redirect. but this is not redirecting for some unclear reason.

Here is how i am using the method:

// in the routes folder

export const onPost: RequestHandler = async (requestEvent) => { 
  const data = await serverNotes();
  data.notes = [
    ...data.notes,
    { id: (data.notes.length + 1).toString(), title: "", text: "" }
  ];
  throw requestEvent.redirect(302, `/dashboard/`);
  throw requestEvent.redirect(302, `/dashboard/notes/${data.notes.length}`);
}

export const factoryFetch = async (method: "DELETE" | "PUT" | "POST", id: string | undefined) => {
  const response = await fetch(`/dashboard/notes/`, {
    method: method,
    headers: {
      "Content-Type": "application/json",
    },
    redirect: "follow", // manual, *follow, error
    body: JSON.stringify({ id: id }),
  });
  return response
}

export const fetchPost = async () => {
  return factoryFetch("POST", undefined)
}
// this code in the component i want to call it from
import { fetchPost } from "~/<your path>";

<p class="text-4xl font-semibold text-sky-950/70 [text-wrap:balance] w-fit">
  Your Next Great Idea Starts Here
</p>
<Button onClick$={async () => {
  await fetchPost();
}}>
  New note
</Button>

Reproduction

https://github.com/barel-mishal/onPostIssue

Steps to reproduce

Run after cloning the project.

npm install npm start

System Info

System:
    OS: macOS 14.4
    CPU: (8) arm64 Apple M2
    Memory: 111.81 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.7.1 - /opt/homebrew/bin/node
    npm: 10.5.0 - /opt/homebrew/bin/npm
    bun: 1.0.30 - ~/.bun/bin/bun
    Watchman: 2024.04.01.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 123.0.6312.107
    Safari: 17.4
  npmPackages:
    @builder.io/qwik: ^1.5.2 => 1.5.2 
    @builder.io/qwik-city: ^1.5.2 => 1.5.2 
    undici: * => 6.12.0 
    vite: ^5.1.6 => 5.2.8

Additional Information

click on the button you will never go to posty
Hope it will be fixed soon I use this pattren a lot

@barel-mishal barel-mishal added STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working labels Apr 10, 2024
@barel-mishal barel-mishal changed the title [🐞] onPost not working properly [🐞] onPost not working properly and delete too Apr 10, 2024
@barel-mishal barel-mishal changed the title [🐞] onPost not working properly and delete too [🐞] onPost not working properly Apr 10, 2024
@gioboa gioboa added WAITING FOR: team Waiting for one of the core team members to review and reply STATUS-2: team is working on this Scheduled for work by the core team and removed STATUS-1: needs triage New issue which needs to be triaged labels Jun 18, 2024
@shairez shairez moved this from Backlog to Upcoming in Qwik Development Jul 30, 2024
@JerryWu1234
Copy link
Contributor

@gioboa are you working for ?

@gioboa
Copy link
Member

gioboa commented Aug 21, 2024

@JerryWu1234 nope, you can take it if you want

@JerryWu1234
Copy link
Contributor

@JerryWu1234 nope, you can take it if you want

Could you offer more detail what I have to do? thanks

@gioboa
Copy link
Member

gioboa commented Aug 22, 2024

throw requestEvent.redirect it's not working correctly inside the code above.
Am I understanding correctly @barel-mishal ?

@JerryWu1234
Copy link
Contributor

JerryWu1234 commented Aug 30, 2024

@gioboa

Image

https://github.com/JerryWu1234/qwik/blob/a9b200527aaf4a83407ab83fc9b2709aac4a801e/packages/qwik-city/src/runtime/src/use-endpoint.ts#L36

I have dug into this for a while.
first of all, accord to above code.
if you want to redirect when using fetch, it seems like it only can be done within fetch .
So this problem occurs because this request is made by using fetch, not from the browser.
@gioboa
Could you please give me some clues about this bug? Thanks

@gioboa
Copy link
Member

gioboa commented Aug 31, 2024

@JerryWu1234 I never looked into that code so I have no clue about it, I'm so sorry 😢
@shairez do you know anything about this?

@QwikDev QwikDev deleted a comment from JerryWu1234 Aug 31, 2024
@JerryWu1234
Copy link
Contributor

I feel this isn't a bug..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATUS-2: team is working on this Scheduled for work by the core team TYPE: bug Something isn't working WAITING FOR: team Waiting for one of the core team members to review and reply
Projects
Status: Backlog
Development

No branches or pull requests

3 participants