Skip to content

Commit babfb4c

Browse files
committedSep 6, 2024··
fix(useId): make generated IDs selector compatible
close #11828
1 parent 72263fa commit babfb4c

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed
 

‎packages/runtime-core/__tests__/helpers/useId.spec.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('useId', () => {
5959
const app = createApp(BasicComponentWithUseId)
6060
return [app, []]
6161
}),
62-
).toBe('v:0 v:1')
62+
).toBe('v-0 v-1')
6363
})
6464

6565
test('with config.idPrefix', async () => {
@@ -69,7 +69,7 @@ describe('useId', () => {
6969
app.config.idPrefix = 'foo'
7070
return [app, []]
7171
}),
72-
).toBe('foo:0 foo:1')
72+
).toBe('foo-0 foo-1')
7373
})
7474

7575
test('async component', async () => {
@@ -92,9 +92,9 @@ describe('useId', () => {
9292
}
9393

9494
const expected =
95-
'v:0 v:1 ' + // root
96-
'v:0-0 v:0-1 ' + // inside first async subtree
97-
'v:1-0 v:1-1' // inside second async subtree
95+
'v-0 v-1 ' + // root
96+
'v-0-0 v-0-1 ' + // inside first async subtree
97+
'v-1-0 v-1-1' // inside second async subtree
9898
// assert different async resolution order does not affect id stable-ness
9999
expect(await getOutput(() => factory(0, 16))).toBe(expected)
100100
expect(await getOutput(() => factory(16, 0))).toBe(expected)
@@ -137,9 +137,9 @@ describe('useId', () => {
137137
}
138138

139139
const expected =
140-
'v:0 v:1 ' + // root
141-
'v:0-0 v:0-1 ' + // inside first async subtree
142-
'v:1-0 v:1-1' // inside second async subtree
140+
'v-0 v-1 ' + // root
141+
'v-0-0 v-0-1 ' + // inside first async subtree
142+
'v-1-0 v-1-1' // inside second async subtree
143143
// assert different async resolution order does not affect id stable-ness
144144
expect(await getOutput(() => factory(0, 16))).toBe(expected)
145145
expect(await getOutput(() => factory(16, 0))).toBe(expected)
@@ -188,9 +188,9 @@ describe('useId', () => {
188188

189189
const expected =
190190
'<div>' +
191-
'v:0 v:1 ' + // root
192-
'v:0-0 v:0-1 ' + // inside first async subtree
193-
'v:1-0 v:1-1' + // inside second async subtree
191+
'v-0 v-1 ' + // root
192+
'v-0-0 v-0-1 ' + // inside first async subtree
193+
'v-1-0 v-1-1' + // inside second async subtree
194194
'</div>'
195195
// assert different async resolution order does not affect id stable-ness
196196
expect(await getOutput(() => factory(0, 16))).toBe(expected)
@@ -232,10 +232,10 @@ describe('useId', () => {
232232
}
233233

234234
const expected =
235-
'v:0 ' + // One
236-
'v:0-0 ' + // Two
237-
'v:0-0-0 v:0-0-1 ' + // Three + Three nested in Two
238-
'v:0-1' // Three after Two
235+
'v-0 ' + // One
236+
'v-0-0 ' + // Two
237+
'v-0-0-0 v-0-0-1 ' + // Three + Three nested in Two
238+
'v-0-1' // Three after Two
239239
// assert different async resolution order does not affect id stable-ness
240240
expect(await getOutput(() => factory())).toBe(expected)
241241
expect(await getOutput(() => factory())).toBe(expected)
@@ -278,8 +278,8 @@ describe('useId', () => {
278278

279279
const expected =
280280
'<div>' +
281-
'v:0 v:1 ' + // root
282-
'v:0-0-0 v:0-0-1' + // async component inside async setup
281+
'v-0 v-1 ' + // root
282+
'v-0-0-0 v-0-0-1' + // async component inside async setup
283283
'</div>'
284284
// assert different async resolution order does not affect id stable-ness
285285
expect(await getOutput(async () => factory(0, 16))).toBe(expected)

‎packages/runtime-core/src/helpers/useId.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { warn } from '../warning'
77
export function useId(): string | undefined {
88
const i = getCurrentInstance()
99
if (i) {
10-
return (i.appContext.config.idPrefix || 'v') + ':' + i.ids[0] + i.ids[1]++
10+
return (i.appContext.config.idPrefix || 'v') + '-' + i.ids[0] + i.ids[1]++
1111
} else if (__DEV__) {
1212
warn(
1313
`useId() is called when there is no active component ` +

0 commit comments

Comments
 (0)
Please sign in to comment.