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

Boolean breaks interface #686

Closed
6 tasks done
JBtje opened this issue Feb 18, 2024 · 2 comments · Fixed by #688
Closed
6 tasks done

Boolean breaks interface #686

JBtje opened this issue Feb 18, 2024 · 2 comments · Fixed by #688
Labels
bug Something isn't working vue3

Comments

@JBtje
Copy link

JBtje commented Feb 18, 2024

Describe the bug

Add a boolean type prop to your component, select the checkbox in the histoire interface and obtain the below error:

Error: Cannot use 'in' operator to search for 'onUpdate:show' in null

it's not related to v-show, or v-if. Having the boolean on its own and selecting it, triggers the error.

Reproduction

https://stackblitz.com/edit/histoire-vue3-starter-tkzdzp

System Info

Browsers:
    Chrome: 121.0.6167.161
  npmPackages:
    @histoire/plugin-vue: ^0.17.11 => 0.17.11
    @vitejs/plugin-vue: ^5.0.3 => 5.0.3
    histoire: ^0.17.9 => 0.17.9
    vite: ^5.0.12 => 5.0.12

Used Package Manager

yarn

Validations

@JBtje JBtje added the to triage This issue needs to be triaged label Feb 18, 2024
Copy link

stackblitz bot commented Feb 18, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@DrJume
Copy link
Contributor

DrJume commented Feb 21, 2024

We also experienced this bug. It only breaks the SourceCodePreview and it only happens, when no attributes or props are set on a the component of the story:

<Story>
  <MyComponent></MyComponent>
</Story>

Even setting an aria-label="test" makes it work again.

The issue lies here:

// @ts-ignore
const vmodelListener = vmodelListeners.find(key => vnode.dynamicProps?.includes(key) || key in vnode.props)

Because @ts-ignore is set and the project doesn't use TypeScript strict mode, the access to vnode.props is not marked as unsafe, as it can be null!

Just checking if vnode.props is truthy is enough to fix the bug:

- // @ts-ignore
- const vmodelListener = vmodelListeners.find(key => vnode.dynamicProps?.includes(key) || key in vnode.props)
+ const vmodelListener = vmodelListeners.find(key => vnode.dynamicProps?.includes(key) || (vnode.props && key in vnode.props))

Sadly the source code in the npm package is minified, but we still managed to patch it with pnpm:

diff --git a/dist/bundled/client/codegen.js b/dist/bundled/client/codegen.js
index 6b922b51e716d6e5df1d0efd8358cbbf36f656c5..13ccbaa62998ae2b7e7934b6303a20dd74223249 100644
--- a/dist/bundled/client/codegen.js
+++ b/dist/bundled/client/codegen.js
@@ -38,7 +38,7 @@ async function k(e, o = null) {
         t.startsWith("on") && (f = "@");
         const L = f === "@" ? `${t[2].toLowerCase()}${t.slice(3)}` : t, M = [`onUpdate:${t}`, `onUpdate:${N(t)}`].find((p) => {
           var $;
-          return (($ = e.dynamicProps) == null ? void 0 : $.includes(p)) || p in e.props;
+          return (($ = e.dynamicProps) == null ? void 0 : $.includes(p)) || (e.props && p in e.props);
         });
         if (f === ":" && M) {
           j.push(M);

DrJume added a commit to DrJume/histoire that referenced this issue Feb 21, 2024
DrJume added a commit to DrJume/histoire that referenced this issue Feb 21, 2024
Fixes histoire-dev#686

Co-authored-by: Louis Haftmann <30736553+LouisHaftmann@users.noreply.github.com>
@Akryum Akryum added bug Something isn't working vue3 and removed to triage This issue needs to be triaged labels Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vue3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants