Skip to content

Commit e83b1ef

Browse files
authored
fix(core): check if injected state matches options and scope id (#1562)
* fix(core): prefer options id when finding state Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * fix(core): check if injected state matches options id Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(changeset): add Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --------- Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
1 parent 6d9535a commit e83b1ef

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

.changeset/beige-shoes-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": patch
3+
---
4+
5+
Check if injected vue flow state matches options id, otherwise create new state

.changeset/funny-jokes-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": patch
3+
---
4+
5+
Prefer options id over scope id when finding vue flow internal state by id

packages/core/src/composables/useVueFlow.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function useVueFlow(idOrOpts?: any): VueFlowStore {
3333
const options = isOptsObj ? idOrOpts : { id: idOrOpts }
3434

3535
const id = options.id
36-
const vueFlowId = scope?.vueFlowId || id
36+
const vueFlowId = id ?? scope?.vueFlowId
3737

3838
let vueFlow: Injection
3939

@@ -42,9 +42,9 @@ export function useVueFlow(idOrOpts?: any): VueFlowStore {
4242
* this should be the regular way after initialization
4343
*/
4444
if (scope) {
45-
const injection = inject(VueFlow, null)
46-
if (typeof injection !== 'undefined' && injection !== null) {
47-
vueFlow = injection
45+
const injectedState = inject(VueFlow, null)
46+
if (typeof injectedState !== 'undefined' && injectedState !== null && (!vueFlowId || injectedState.id === vueFlowId)) {
47+
vueFlow = injectedState
4848
}
4949
}
5050

@@ -63,7 +63,7 @@ export function useVueFlow(idOrOpts?: any): VueFlowStore {
6363
* _or_ if the store instance we found does not match up with provided ids
6464
* create a new store instance and register it in storage
6565
*/
66-
if (!vueFlow || (vueFlow && id && id !== vueFlow.id)) {
66+
if (!vueFlow || (vueFlowId && vueFlow.id !== vueFlowId)) {
6767
const name = id ?? storage.getId()
6868

6969
const state = storage.create(name, options)

0 commit comments

Comments
 (0)