From 275c2cdd85e9ced4e39c77f87741d32c8f08fe95 Mon Sep 17 00:00:00 2001 From: Ben Hong Date: Tue, 8 Jul 2025 09:24:12 -0400 Subject: [PATCH 1/2] docs: add addendum on useId usage with computed --- src/api/composition-api-helpers.md | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/api/composition-api-helpers.md b/src/api/composition-api-helpers.md index 3fe24aad64..789b0f7647 100644 --- a/src/api/composition-api-helpers.md +++ b/src/api/composition-api-helpers.md @@ -42,10 +42,11 @@ This is the underlying helper that powers [`defineModel()`](/api/sfc-script-setu set?: (v: T) => any } - type ModelRef = Ref & [ - ModelRef, - Record - ] + type ModelRef = Ref< + G, + S + > & + [ModelRef, Record] ``` - **Example** @@ -132,3 +133,18 @@ Used to generate unique-per-application IDs for accessibility attributes or form IDs generated by `useId()` are also guaranteed to be stable across the server and client renders, so they can be used in SSR applications without leading to hydration mismatches. If you have more than one Vue application instance of the same page, you can avoid ID conflicts by giving each app an ID prefix via [`app.config.idPrefix`](/api/application#app-config-idprefix). + + :::warning Caution + `useId()` should be not be called inside a `computed()` property as it may cause instance conflicts. Instead, declare the ID outside of `computed()` and reference it within the computed function. + + ```vue + + ``` + + ::: From 516cbfb8ffa3863c5460da8ed8e1a46a41aa5266 Mon Sep 17 00:00:00 2001 From: Ben Hong Date: Tue, 15 Jul 2025 14:21:36 -0400 Subject: [PATCH 2/2] docs: refine useId warning with computed --- src/api/composition-api-helpers.md | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/api/composition-api-helpers.md b/src/api/composition-api-helpers.md index 789b0f7647..285ce4d31e 100644 --- a/src/api/composition-api-helpers.md +++ b/src/api/composition-api-helpers.md @@ -42,11 +42,10 @@ This is the underlying helper that powers [`defineModel()`](/api/sfc-script-setu set?: (v: T) => any } - type ModelRef = Ref< - G, - S - > & - [ModelRef, Record] + type ModelRef = Ref & [ + ModelRef, + Record + ] ``` - **Example** @@ -136,15 +135,4 @@ Used to generate unique-per-application IDs for accessibility attributes or form :::warning Caution `useId()` should be not be called inside a `computed()` property as it may cause instance conflicts. Instead, declare the ID outside of `computed()` and reference it within the computed function. - - ```vue - - ``` - :::