Skip to content

Commit

Permalink
Merge pull request #952 from 3YOURMIND/hack-fix-breaking-tippy-import
Browse files Browse the repository at this point in the history
hack(vue-use-tippy): make sure tippy is always a function
  • Loading branch information
Isokaeder authored Jun 21, 2024
2 parents 009f2dc + 743e57c commit f99db54
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/vue-use-tippy/source/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import castArray from 'lodash.castarray'
import type { Props, Instance } from 'tippy.js'
import tippy from 'tippy.js'
import _tippy from 'tippy.js'
import type { Ref } from 'vue'
import { onMounted, ref, onUnmounted, watch } from 'vue'

/**
* HACK: This hacky evaluation to tippy at runtime should just be
* ```js
* import tippy from 'tippy.js'
* ```
*
* However, there is a strange bug for some user apps, that will load
* vue-use-tippy as ESM but tippy.js as CJS. If that happens, they
* will see a error akin to "tippy is not a function".
*
* If tippy is not already (correctly) a function, we guess it might
* be on `.default`
*/
const tippy =
typeof _tippy === 'function'
? _tippy
: (_tippy as unknown as { default: typeof _tippy }).default

type InstanceRefType = Instance[] | Instance | null
type Callback = (t: InstanceRefType) => void
type Target = Ref<Element | null>
Expand Down

0 comments on commit f99db54

Please sign in to comment.