Skip to content

refactor(kit): processInject#1112

Open
skirtles-code wants to merge 1 commit into
vuejs:mainfrom
skirtles-code:processInject
Open

refactor(kit): processInject#1112
skirtles-code wants to merge 1 commit into
vuejs:mainfrom
skirtles-code:processInject

Conversation

@skirtles-code

Copy link
Copy Markdown
Contributor

There were a few things about processInject that caught my eye, which I've attempted to address here.

// eslint-disable-next-line no-prototype-builtins
value: returnError(() => instance.ctx.hasOwnProperty(key) ? instance.ctx[key] : instance.provides.hasOwnProperty(originalKey) ? instance.provides[originalKey] : defaultValue),

instance.provides uses Object.create(null), so accessing instance.provides.hasOwnProperty will throw an error. In practice, it's quite difficult to hit that error, and the error is caught by returnError, but nevertheless, instance.provides.hasOwnProperty will never succeed.

Due to that error, the defaultValue is never actually used. However, even if it were used, there are some problems with that value. The logic for setting defaultValue leads to it being shared between all injections, so if multiple injections attempt to set a default it will just use the final value as the value for all injections. It also doesn't account for when the default is a factory function. In practice, we can just remove all the code related to default. Vue will set the default on instance.ctx, so we don't need any special handling for it in the devtools.

I made this change to ensure originalKey is always set:

- originalKey = value.from
+ originalKey = value.from ?? key

That allows the later check for originalKey && key !== originalKey to be simplified to just key !== originalKey.

I've switched a few calls from x.toString() to use String(x) instead. I think that's generally regarded more idiomatic, handling a wider range of values safely. Vue core uses that pattern extensively. In practice, I don't think it matters in this specific code, but String(x) saves us having to worry about edge cases, especially as the values have type any.

I've also extracted a separate hasOwn function. The code for that function comes from Vue core. Using a separate function like this avoids any of the risks associated with Object.create(null). That function can be moved to a shared location and reused elsewhere, but I thought it'd be better to do that in a separate PR, rather than expanding the scope of this refactoring to other files.

Using hasOwn allows the eslint-disable-next-line to be removed.

I've retained the call to returnError, as that seems to be a pattern used throughout this file, but in practice I don't think the new code will throw any errors.

@netlify

netlify Bot commented Jul 18, 2026

Copy link
Copy Markdown

Deploy Preview for vue-devtools-docs canceled.

Name Link
🔨 Latest commit 77c2923
🔍 Latest deploy log https://app.netlify.com/projects/vue-devtools-docs/deploys/6a5c0287c81edb0008a8364f

@pkg-pr-new

pkg-pr-new Bot commented Jul 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/devtools-applet

npm i https://pkg.pr.new/@vue/devtools-applet@1112

@vue/devtools-core

npm i https://pkg.pr.new/@vue/devtools-core@1112

@vue/devtools

npm i https://pkg.pr.new/@vue/devtools@1112

@vue/devtools-api

npm i https://pkg.pr.new/@vue/devtools-api@1112

@vue/devtools-kit

npm i https://pkg.pr.new/@vue/devtools-kit@1112

@vue/devtools-electron

npm i https://pkg.pr.new/@vue/devtools-electron@1112

@vue/devtools-shared

npm i https://pkg.pr.new/@vue/devtools-shared@1112

@vue/devtools-ui

npm i https://pkg.pr.new/@vue/devtools-ui@1112

vite-plugin-vue-devtools

npm i https://pkg.pr.new/vite-plugin-vue-devtools@1112

commit: 77c2923

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant