Skip to content

Commit 7e021f6

Browse files
committed
Always generates an instance id for webviews
1 parent 98ffe86 commit 7e021f6

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/webviews/webviewCommandRegistrar.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ export class WebviewCommandRegistrar implements Disposable {
3737
return;
3838
}
3939

40-
const key = context.webviewInstance
41-
? `${context.webview}:${context.webviewInstance}`
42-
: context.webview;
40+
const key =
41+
context.webviewInstance && instanceId
42+
? `${context.webview}:${context.webviewInstance}`
43+
: context.webview;
4344

4445
const handler = handlers.get(key);
4546
if (handler == null) {

src/webviews/webviewController.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class WebviewController<
9494
container: Container,
9595
commandRegistrar: WebviewCommandRegistrar,
9696
descriptor: WebviewPanelDescriptor<ID>,
97-
instanceId: string | undefined,
97+
instanceId: string,
9898
parent: WebviewPanel,
9999
resolveProvider: (
100100
container: Container,
@@ -110,7 +110,7 @@ export class WebviewController<
110110
container: Container,
111111
commandRegistrar: WebviewCommandRegistrar,
112112
descriptor: WebviewViewDescriptor<ID>,
113-
instanceId: string | undefined,
113+
instanceId: string,
114114
parent: WebviewView,
115115
resolveProvider: (
116116
container: Container,
@@ -126,7 +126,7 @@ export class WebviewController<
126126
container: Container,
127127
commandRegistrar: WebviewCommandRegistrar,
128128
descriptor: GetWebviewDescriptor<ID>,
129-
instanceId: string | undefined,
129+
instanceId: string,
130130
parent: GetWebviewParent<ID>,
131131
resolveProvider: (
132132
container: Container,
@@ -173,7 +173,7 @@ export class WebviewController<
173173
private readonly container: Container,
174174
private readonly _commandRegistrar: WebviewCommandRegistrar,
175175
private readonly descriptor: GetWebviewDescriptor<ID>,
176-
public readonly instanceId: string | undefined,
176+
public readonly instanceId: string,
177177
public readonly parent: GetWebviewParent<ID>,
178178
resolveProvider: (
179179
container: Container,
@@ -240,7 +240,14 @@ export class WebviewController<
240240
command: WebviewCommands | WebviewViewCommands,
241241
callback: WebviewCommandCallback<T>,
242242
): Disposable {
243-
return this._commandRegistrar.registerCommand(this.provider, this.id, this.instanceId, command, callback);
243+
return this._commandRegistrar.registerCommand(
244+
this.provider,
245+
this.id,
246+
// We should be able to remove this in the future and always use the instanceId, but we need to do more testing to make sure each webview command always comes with the instanceId
247+
this.descriptor.allowMultipleInstances ? this.instanceId : undefined,
248+
command,
249+
callback,
250+
);
244251
}
245252

246253
private _initializing: Promise<void> | undefined;

src/webviews/webviewsController.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export interface WebviewPanelProxy<
5555
SerializedState = unknown,
5656
> extends Disposable {
5757
readonly id: ID;
58-
readonly instanceId: string | undefined;
58+
readonly instanceId: string;
5959
readonly ready: boolean;
6060
readonly active: boolean;
6161
readonly visible: boolean;
@@ -96,6 +96,8 @@ export interface WebviewViewDescriptor<ID extends WebviewViewIds = WebviewViewId
9696
readonly webviewHostOptions?: {
9797
readonly retainContextWhenHidden?: boolean;
9898
};
99+
100+
readonly allowMultipleInstances?: never;
99101
}
100102

101103
interface WebviewViewRegistration<
@@ -192,7 +194,7 @@ export class WebviewsController implements Disposable {
192194
this.container,
193195
this._commandRegistrar,
194196
descriptor,
195-
undefined,
197+
uuid(),
196198
webviewView,
197199
resolveProvider,
198200
);
@@ -346,7 +348,7 @@ export class WebviewsController implements Disposable {
346348
container,
347349
commandRegistrar,
348350
descriptor,
349-
descriptor.allowMultipleInstances ? uuid() : undefined,
351+
uuid(),
350352
panel,
351353
resolveProvider,
352354
);

0 commit comments

Comments
 (0)