Skip to content

Commit d098f16

Browse files
authored
Merge branch 'vitejs:main' into main
2 parents 29f3b93 + d39c659 commit d098f16

24 files changed

Lines changed: 108 additions & 16 deletions

File tree

docs/kit/rpc.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,22 @@ export default function setup(ctx: DockClientScriptContext) {
393393
}
394394
```
395395

396+
### Global Client Context
397+
398+
Use `getDevToolsClientContext()` to access the client context (`DevToolsClientContext`) from anywhere on the client side. This is set automatically when DevTools initializes in embedded or standalone mode.
399+
400+
```ts
401+
import { getDevToolsClientContext } from '@vitejs/devtools-kit/client'
402+
403+
const ctx = getDevToolsClientContext()
404+
if (ctx) {
405+
const modules = await ctx.rpc.call('my-plugin:get-modules')
406+
}
407+
```
408+
409+
Returns `undefined` if the context has not been initialized yet.
410+
```
411+
396412
## Client-Side Functions
397413
398414
You can also define functions on the client that the server can call.

docs/kit/shared-state.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ const state = await client.sharedState.get('my-plugin:state')
118118
console.log(state.value())
119119
```
120120

121+
You can also access shared state through the global client context:
122+
123+
```ts
124+
import { getDevToolsClientContext } from '@vitejs/devtools-kit/client'
125+
126+
const ctx = getDevToolsClientContext()
127+
if (ctx) {
128+
const state = await ctx.rpc.sharedState.get('my-plugin:state')
129+
}
130+
```
131+
121132
### Subscribing to Changes
122133

123134
Use `state.on('updated', ...)` to react to state changes:

examples/plugin-a11y-checker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "example-plugin-a11y-checker",
33
"type": "module",
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"private": true,
66
"exports": {
77
".": "./dist/index.mjs",

examples/plugin-file-explorer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "example-plugin-file-explorer",
33
"type": "module",
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"private": true,
66
"exports": {
77
".": "./dist/index.mjs",

examples/plugin-git-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "example-plugin-git-ui",
33
"type": "module",
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"private": true,
66
"exports": {
77
".": "./dist/index.mjs",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"type": "module",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"private": true,
55
"packageManager": "pnpm@10.32.1",
66
"scripts": {

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vitejs/devtools",
33
"type": "module",
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"description": "Vite DevTools",
66
"author": "VoidZero Inc.",
77
"license": "MIT",

packages/core/playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "playground",
33
"type": "module",
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"private": true,
66
"scripts": {
77
"dev": "DEBUG='vite:devtools:*' VITE_DEVTOOLS_LOCAL_DEV=true vite",

packages/core/src/client/inject/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// <reference lib="dom" />
33

44
import type { DockPanelStorage } from '@vitejs/devtools-kit/client'
5-
import { getDevToolsRpcClient } from '@vitejs/devtools-kit/client'
5+
import { CLIENT_CONTEXT_KEY, getDevToolsRpcClient } from '@vitejs/devtools-kit/client'
66
import { useLocalStorage } from '@vueuse/core'
77
import { createDocksContext } from '../webcomponents/state/context'
88

@@ -31,6 +31,7 @@ export async function init(): Promise<void> {
3131
rpc,
3232
state,
3333
)
34+
;(globalThis as any)[CLIENT_CONTEXT_KEY] = context
3435

3536
const { DockEmbedded } = import.meta.env.VITE_DEVTOOLS_LOCAL_DEV
3637
? await import('../webcomponents')

packages/core/src/client/standalone/App.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import type { DocksContext } from '@vitejs/devtools-kit/client'
3-
import { getDevToolsRpcClient } from '@vitejs/devtools-kit/client'
3+
import { CLIENT_CONTEXT_KEY, getDevToolsRpcClient } from '@vitejs/devtools-kit/client'
44
import DockStandalone from '../webcomponents/components/DockStandalone.vue'
55
import { createDocksContext } from '../webcomponents/state/context'
66
@@ -13,6 +13,7 @@ const context: DocksContext = await createDocksContext(
1313
'standalone',
1414
rpc,
1515
)
16+
;(globalThis as any)[CLIENT_CONTEXT_KEY] = context
1617
</script>
1718

1819
<template>

0 commit comments

Comments
 (0)