formkit: After Update to Vue 3.5.x FormKitSchema cleanup on unmount throws Exception

Reproduction

https://github.com/formkit/formkit/blob/6b4542a3e013bfff810e126eb20eb2fbce6f25af/packages/vue/src/FormKitSchema.ts

Describe the bug

Hi,

sorry for passing only the link to the code where the exception is thrown, but you need some more complex application where you toggle between multiple components that includes a FormkitSchema component.

After switching to Vue 3.5 it seems that data on cleanup can be null.

    /**
     * Perform cleanup operations when the component is unmounted. This should
     * remove any memory allocations that were made during the render process.
     */
    function cleanUp() {
      // Perform cleanup operations
      clean(props.schema, props.memoKey, instanceKey)
      /* eslint-disable @typescript-eslint/no-non-null-assertion */
      if (data.node) data.node.destroy()
      data.slots = null!
      data = null!
      render = null!
      /* eslint-enable @typescript-eslint/no-non-null-assertion */
    }```

Access data.node throws part throws exception:

Uncaught (in promise) TypeError: Cannot read properties of null (reading ‘node’) at cleanUp (@formkit_vue.js?v=c3cff561:1581:16) at chunk-CXSE3S54.js?v=c3cff561:4847:40 at callWithErrorHandling (chunk-CXSE3S54.js?v=c3cff561:2288:19) at callWithAsyncErrorHandling (chunk-CXSE3S54.js?v=c3cff561:2295:17) at hook.__weh.hook.__weh (chunk-CXSE3S54.js?v=c3cff561:4827:19) at flushPostFlushCbs (chunk-CXSE3S54.js?v=c3cff561:2474:28) at flushJobs (chunk-CXSE3S54.js?v=c3cff561:2516:5)


Changing back to Vue 3.4 fix the issue.

Greetings,

Tom
 

### Environment

• OS: MacOS 14.6.1
• Browser Chrome
• Version 128.0.6613.120 (Offizieller Build) (arm64)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 17 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@jpcarpenter can you checkout 1.6.7? I think this is fixed there now.

Hi Justin, thank you for your fix!

At the moment it fixes my reported problem so i can update to Vue 3.5 (Nuxt 3.13).

Forms with FormKit are a great fun and so useful !

Have a great coding time,

Tom

All seems well now! Thanks for taking the time looking into this!

It looks like it’s something to do with Vue 3.5.6. I changed my Vue version from having "vue": "^3.5", to "vue": "3.5.5", and the error no longer appears. All my formkit versions are set to 1.6.6 as well.

The Vue changelog for 3.5.6 mentions some updates to reactivity and how it relies on a dirty check when computed has deps:

reactivity: rely on dirty check only when computed has deps (https://github.com/vuejs/core/issues/11931) (aa5dafd), closes https://github.com/vuejs/core/issues/11929

That’s the one thing that stuck out to me based on the context of the error message I was receiving. I could be completely wrong however.

I was encountering this same issue with my Nuxt 3 project. After updating to 1.6.6, I now get a fatal error on page loads:

500
Cannot read properties of null (reading 'props')

at refreshComputed (./node_modules/@vue/reactivity/dist/reactivity.cjs.js:365:28)
at isDirty (./node_modules/@vue/reactivity/dist/reactivity.cjs.js:335:68)
at get dirty [as dirty] (./node_modules/@vue/reactivity/dist/reactivity.cjs.js:268:12)
at job (./node_modules/@vue/reactivity/dist/reactivity.cjs.js:1811:40)
at callWithErrorHandling (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:33)
at flushJobs (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:408:9)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

The Nuxt DevTools gives an additional line in the stack trace on the first line:

Screenshot 2024-09-17 at 3 38 50 PM

Which points here within ./node_modules/@formkit/vue/dist/index.dev.mjs

fns: {
  length: (obj) => Object.keys(obj).length,
  number: (value2) => Number(value2),
  string: (value2) => String(value2), // <--- points here
  json: (value2) => JSON.stringify(value2),
  eq: eq
},

The weird thing is the error disappears whenever I remove the help prop from any/all FormKit inputs on the page…

<FormKit
  type="email"
  label="Busniess Email Address"
  name="businessEmailAddress"
  help="The primary email address for the business."  // <--- error disappears when help prop is removed
  validation="required|email"
  validation-visibility="blur"
  placeholder="name@business.com"
/>

My package.json is as follows:

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "dependencies": {
    "@formkit/addons": "^1.6.5",
    "@formkit/drag-and-drop": "^0.1.6",
    "@formkit/icons": "^1.6.5",
    "@formkit/pro": "^0.127.0",
    "@pinia/nuxt": "^0.5.3",
    "graphql": "^16.9.0",
    "graphql-tag": "^2.12.6",
    "jsonwebtoken": "^9.0.2",
    "nuxt": "^3.13.2",
    "pinia": "^2.2.2",
    "vue": "^3.5",
    "vue3-google-map": "^0.21.0",
    "vue3-toastify": "^0.2.2"
  },
  "devDependencies": {
    "@formkit/auto-animate": "^0.8.2",
    "@formkit/nuxt": "^1.6.6",
    "@iconify-json/heroicons-solid": "^1.1.11",
    "@nuxt/icon": "^1.4.5",
    "@nuxtjs/google-fonts": "^3.2.0",
    "@nuxtjs/tailwindcss": "^6.12.1",
    "@pinia-plugin-persistedstate/nuxt": "^1.2.1",
    "@tailwindcss/forms": "^0.5.7",
    "@types/google.maps": "^3.58.0",
    "@types/jsonwebtoken": "^9.0.6",
    "@vueuse/nuxt": "^10.11.1",
    "sass": "^1.77.8",
    "typescript": "^5.5.4"
  }
}

Ok, i just published 1.6.6 that should fix this. Please report if you have further/different 3.5 related issues.