QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.85k stars 1.31k forks source link

[๐Ÿž] V2 - Promises not expected here #7000

Closed ianlet closed 3 weeks ago

ianlet commented 3 weeks ago

Which component is affected?

Qwik Runtime

Describe the bug

Introduced in Qwik V2, the error Promises not expected here. is thrown when rendering a component with a conditional projection that is async.

For example:

// File: src/routes/index.tsx

export default component$(() => {
  const open = useSignal(false);

  return (
    <TheCursedReveal open={open.value}>
      {t("I am an async string")}
    </TheCursedReveal>
  );
});

const TheCursedReveal = component$<{
  open: boolean;
}>(({ open }) => {
  return <>{open && <Slot />}</>;
});

async function t(key: string): Promise<string> {
  return Promise.resolve(key);
}

Any other variants of a <Slot /> being conditionally rendered will give the same error. For example:

const TheOtherCursedReveal = component$<{
  open: boolean;
}>(({ open }) => {
  if (!open) return null;

  return (
    <div>
      <Slot />
    </div>
  );
});

Additionally, the error is so obscure that it doesn't help at all to understand where and why this error is triggered:

QWIK ERROR Promises not expected here. Error: Promises not expected here.
    at createAndLogError (/home/ian/Projects/noma/node_modules/.pnpm/@builder.io+qwik@file+..+oss+qwik+packages+qwik_prettier@3.3.3_vite@5.4.9_@types+node@22.7.7__3o4nugbb2q2oqnvka6jhcm2faq/node_modules/@builder.io/qwik/dist/core.mjs:53:52)
    at throwErrorAndStop (/home/ian/Projects/noma/node_modules/.pnpm/@builder.io+qwik@file+..+oss+qwik+packages+qwik_prettier@3.3.3_vite@5.4.9_@types+node@22.7.7__3o4nugbb2q2oqnvka6jhcm2faq/node_modules/@builder.io/qwik/dist/core.mjs:28:17)
    at drain (/home/ian/Projects/noma/node_modules/.pnpm/@builder.io+qwik@file+..+oss+qwik+packages+qwik_prettier@3.3.3_vite@5.4.9_@types+node@22.7.7__3o4nugbb2q2oqnvka6jhcm2faq/node_modules/@builder.io/qwik/dist/core.mjs:3202:20)
    at Module._walkJSX (/home/ian/Projects/noma/node_modules/.pnpm/@builder.io+qwik@file+..+oss+qwik+packages+qwik_prettier@3.3.3_vite@5.4.9_@types+node@22.7.7__3o4nugbb2q2oqnvka6jhcm2faq/node_modules/@builder.io/qwik/dist/core.mjs:3226:3)
    at SSRContainer.emitUnclaimedProjection (/home/ian/Projects/noma/node_modules/.pnpm/@builder.io+qwik@file+..+oss+qwik+packages+qwik_prettier@3.3.3_vite@5.4.9_@types+node@22.7.7__3o4nugbb2q2oqnvka6jhcm2faq/node_modules/@builder.io/qwik/dist/server.mjs:8721:35)
    at SSRContainer.emitContainerData (/home/ian/Projects/noma/node_modules/.pnpm/@builder.io+qwik@file+..+oss+qwik+packages+qwik_prettier@3.3.3_vite@5.4.9_@types+node@22.7.7__3o4nugbb2q2oqnvka6jhcm2faq/node_modules/@builder.io/qwik/dist/server.mjs:8414:10)
    at SSRContainer.closeElement (/home/ian/Projects/noma/node_modules/.pnpm/@builder.io+qwik@file+..+oss+qwik+packages+qwik_prettier@3.3.3_vite@5.4.9_@types+node@22.7.7__3o4nugbb2q2oqnvka6jhcm2faq/node_modules/@builder.io/qwik/dist/server.mjs:8239:24)
    at drain (/home/ian/Projects/noma/node_modules/.pnpm/@builder.io+qwik@file+..+oss+qwik+packages+qwik_prettier@3.3.3_vite@5.4.9_@types+node@22.7.7__3o4nugbb2q2oqnvka6jhcm2faq/node_modules/@builder.io/qwik/dist/core.mjs:3207:31)
    at resolveValue (/home/ian/Projects/noma/node_modules/.pnpm/@builder.io+qwik@file+..+oss+qwik+packages+qwik_prettier@3.3.3_vite@5.4.9_@types+node@22.7.7__3o4nugbb2q2oqnvka6jhcm2faq/node_modules/@builder.io/qwik/dist/core.mjs:3189:5)
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Additional Information

Debugging:

Varixo commented 3 weeks ago

Nice catch! Thank you for the reproduction ๐Ÿ˜„ Should be fixed now