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

Exporting a default component from an endpoint makes onPut unreachable #1411

Closed
mglikesbikes opened this issue Sep 23, 2022 · 0 comments · Fixed by #2233
Closed

Exporting a default component from an endpoint makes onPut unreachable #1411

mglikesbikes opened this issue Sep 23, 2022 · 0 comments · Fixed by #2233
Assignees
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working
Milestone

Comments

@mglikesbikes
Copy link

Qwik Version

0.9.0

Operating System (or Browser)

Cloudflare pages adapter

Node Version (if applicable)

No response

Which component is affected?

Qwik City

Expected Behaviour

Seeing some weird behavior with endpoints. Or rather — unexpected behavior. Consider the following:

// src/routes/test/index.tsx:

import { component$ } from '@builder.io/qwik';
import { RequestHandler } from '@builder.io/qwik-city';
export const onPut: RequestHandler = async () => {
  console.log(`you'll always see this`);
  return {
    success: false,
    error: "hello from onPut",
  };
};

const Index = component$(() => {
  return <div>hi</div>;
});

export default Index; <-- problem line

Calling it:

// src/routes/index.tsx
    <button
        onClick$={async () => {
          const res = await fetch("/test", {
            method: "put",
            headers: {
              "Content-Type": "application/json",
            },
            body: JSON.stringify({ foo: "bar" }),
          });
          console.log("-->", await res.json());
        }}>
        PUT
    </button>

Actual Behaviour

When the export default line is removed, onPut works fine. With that line in, I see the following:

  • onPut() continues to invoke;
  • onPut() does not return the correct value.

Screenshots below — first, the export default line is commented out and the fetch runs as expected. Next, I uncomment it and fire the fetch again after it's built in the background.

Screen Shot 2022-09-22 at 9 38 35 PM

_`export default` is commented out, `fetch()` works fine_

Screen Shot 2022-09-22 at 9 38 58 PM

_`export default` is commented in, `fetch()` explodes

Additional Information

As mentioned — I'm using the cloudflare pages adapter. I've deviated from the standard build scripts though, running the following in two terminals:

  • qwik build (via npm-watch package, fired when files change)
  • npx wrangler@beta pages dev ./dist --port 3000 (picks up changes to functions/ and dist/ and does whatever wrangler does to preview local content)
@mglikesbikes mglikesbikes added TYPE: bug Something isn't working STATUS-1: needs triage New issue which needs to be triaged labels Sep 23, 2022
@manucorporat manucorporat added this to the 0.10.0 milestone Sep 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants