Skip to content

Commit

Permalink
fix(runtime-core): correctly assign suspenseId to avoid conflicts wit…
Browse files Browse the repository at this point in the history
…h the default id (#9966)

close #9944
  • Loading branch information
yangxiuxiu1115 committed Jan 3, 2024
1 parent a47fb45 commit 0648804
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/runtime-core/__tests__/components/Suspense.spec.ts
Expand Up @@ -24,12 +24,14 @@ import {
} from '@vue/runtime-test'
import { createApp, defineComponent } from 'vue'
import type { RawSlots } from 'packages/runtime-core/src/componentSlots'
import { resetSuspenseId } from '../../src/components/Suspense'

describe('Suspense', () => {
const deps: Promise<any>[] = []

beforeEach(() => {
deps.length = 0
resetSuspenseId()
})

// a simple async factory for testing purposes only.
Expand Down
7 changes: 6 additions & 1 deletion packages/runtime-core/src/components/Suspense.ts
Expand Up @@ -50,6 +50,11 @@ export const isSuspense = (type: any): boolean => type.__isSuspense
// incrementing unique id for every pending branch
let suspenseId = 0

/**
* For testing only
*/
export const resetSuspenseId = () => (suspenseId = 0)

// Suspense exposes a component-like API, and is treated like a component
// in the compiler, but internally it's a special built-in type that hooks
// directly into the renderer.
Expand Down Expand Up @@ -476,7 +481,7 @@ function createSuspenseBoundary(
hiddenContainer,
anchor,
deps: 0,
pendingId: 0,
pendingId: suspenseId++,
timeout: typeof timeout === 'number' ? timeout : -1,
activeBranch: null,
pendingBranch: null,
Expand Down
4 changes: 2 additions & 2 deletions packages/sfc-playground/src/App.vue
Expand Up @@ -140,8 +140,8 @@ onMounted(() => {
:preview-options="{
customCode: {
importCode: `import { initCustomFormatter } from 'vue'`,
useCode: `initCustomFormatter()`
}
useCode: `initCustomFormatter()`,
},
}"
/>
</template>
Expand Down

0 comments on commit 0648804

Please sign in to comment.