add warning when Yjs was already imported
This commit is contained in:
parent
491cd422c4
commit
cbddf6ef90
23
src/index.js
23
src/index.js
@ -1,3 +1,4 @@
|
|||||||
|
/** eslint-env browser */
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Doc,
|
Doc,
|
||||||
@ -84,3 +85,25 @@ export {
|
|||||||
diffUpdate,
|
diffUpdate,
|
||||||
diffUpdateV2
|
diffUpdateV2
|
||||||
} from './internals.js'
|
} from './internals.js'
|
||||||
|
|
||||||
|
const glo = /** @type {any} */ (typeof window !== 'undefined'
|
||||||
|
? window
|
||||||
|
: typeof global !== 'undefined' ? global : {})
|
||||||
|
const importIdentifier = '__ $YJS$ __'
|
||||||
|
|
||||||
|
if (glo[importIdentifier] === true) {
|
||||||
|
/**
|
||||||
|
* Dear reader of this error message.
|
||||||
|
*
|
||||||
|
* If you see this message, please make sure that you only import one version of Yjs. In many cases,
|
||||||
|
* your package manager installs two versions of Yjs that are used by different packages of your project.
|
||||||
|
* Another reason for this message is that some parts of your project use the commonjs version of Yjs
|
||||||
|
* and others use the EcmaScript version of Yjs.
|
||||||
|
*
|
||||||
|
* This very often leads to issues that are hard to debug. We often need to do constructor checks,
|
||||||
|
* e.g. `struct instanceof GC`. If you importent different versions of Yjs, it is impossible for us to
|
||||||
|
* do the constructor checks anymore - which might break the CRDT algorithm.
|
||||||
|
*/
|
||||||
|
console.warn('Yjs was already imported. Importing different versions of Yjs often leads to issues.')
|
||||||
|
}
|
||||||
|
glo[importIdentifier] = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user