QwikDev/qwik

[๐Ÿž] onPost not working properly

barel-mishal opened this issue ยท 0 comments

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