-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
fix(types): restrict provide() key to string | InjectionKey to avoid unexpected key collisions #12999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
/ecosystem-ci run |
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
Size ReportBundles
Usages
|
📝 Ran ecosystem CI: Open
|
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
WalkthroughThe changes update the type constraints for the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant provide (apiInject.ts)
User->>provide (apiInject.ts): provide(key: InjectionKey<T> | string, value: T)
Note right of provide (apiInject.ts): Compile-time error if key is not InjectionKey<T> or string
Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code Graph Analysis (1)packages-private/dts-test/inject.test-d.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (3)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
fix #9439
Overview
This PR updates the type signature of the
provide()
function to accept only two kinds of keys:InjectionKey<T>
(which is asymbol
), andstring
Previously,
provide()
accepted keys of typenumber
or evenobject
. In JavaScript, any non-string, non-symbol key will be implicitly converted to a string. For example:123
becomes the string"123"
."[object Object]"
.These conversions can cause key collisions. Multiple different objects (or numbers, booleans, etc.) might all end up converting to the same string key, overwriting each other’s values. That is obviously unwanted behavior in an API designed for unique injection keys.
Reasoning
string | symbol
is consistent with core JavaScript behavior for object property names – objects use string or symbol keys."[object Object]"
.What Changed
apiInject.ts
, the type ofprovide()
is changed from:key
must be either asymbol
-basedInjectionKey<T>
or astring
, eliminatingnumber
(and others) from the accepted set of types.Benefits
boolean
,object
, ornumber
as keys that silently collide after string conversion.string | symbol
for object keys, avoiding inconsistent usage.Overall, this change ensures safer and more predictable behavior when injecting or providing dependencies in Vue, reducing the risk of subtle collisions and bugs.
External Document
Summary by CodeRabbit
provide
function, ensuring only valid key types are accepted.provide
function.