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

destructured useContext 2x causes already declared error #230

Open
intellix opened this issue May 1, 2024 · 0 comments
Open

destructured useContext 2x causes already declared error #230

intellix opened this issue May 1, 2024 · 0 comments

Comments

@intellix
Copy link
Contributor

intellix commented May 1, 2024

Current Behavior

When you destructure 2x useContext in a single component like so:

const { openToast$ } = useContext(ToastApiContextId);
const { openModal$ } = useContext(ModalApiContextId);

Then you get an error like so:

  frame: '\n' +
    '\x1B[33mThe symbol "context" has already been declared\x1B[39m\n' +
    '17 |  const s_1SNzPtcSEoc = ()=>{\n' +
    '18 |      const context = useContext(ToastApiContextId);\n' +
    '19 |      const context = useContext(ModalApiContextId);\n' +
    '   |            ^\n' +
    '20 |      useTaskQrl(/*#__PURE__*/ inlinedQrl(s_4rRz0sN06LY, "s_4rRz0sN06LY", [\n' +
    '21 |          context\n',

Expected Behavior

It should compile/serve/build without a problem (like in a standard qwik project)

GitHub Repo

https://github.com/intellix/qwik-nx-context-2-bug

Steps to Reproduce

  1. npm install
  2. npx nx serve bug --skip-nx-cache (or build)

Nx Report

Node   : 18.20.2
OS     : darwin-arm64
npm    : 6.14.16

nx             : 18.3.4
@nx/js         : 18.3.4
@nx/workspace  : 18.3.4
@nx/devkit     : 18.3.4
@nrwl/tao      : 18.3.4
@nx/vite       : 18.3.4
@nx/web        : 18.3.4
typescript     : 5.4.5
---------------------------------------
Community plugins:
qwik-nx : 2.2.1

Failure Logs

No response

Additional Information

Taken me quite some time to replicate this in a large project, because it works without a problem in a new qwik project on it's own. After deleting 99% of my project and seeing it still happened, I realised that it only happens in a qwik-nx project.

I'm not sure what's different from a regular qwik project but if you copy components/routes then you'll see it works in one.

This workaround doesn't work because I guess it gets collapsed down?

export function useToasterApi() {
  return useContext(ToasterApiContextId);
}

But it works if you make the function more complex so it doesn't get collapsed

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

No branches or pull requests

1 participant