From 6187d2835e3435dd8a927aff76c5d158ca3be292 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 16 Nov 2022 23:37:22 -0500 Subject: [PATCH] Avoids needless re-renders --- src/webviews/webviewViewBase.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/webviews/webviewViewBase.ts b/src/webviews/webviewViewBase.ts index 179fa0a..e551d02 100644 --- a/src/webviews/webviewViewBase.ts +++ b/src/webviews/webviewViewBase.ts @@ -91,6 +91,11 @@ export abstract class WebviewViewBase implements } } + private readonly _cspNonce = getNonce(); + protected get cspNonce(): string { + return this._cspNonce; + } + protected onInitializing?(): Disposable[] | undefined; protected onReady?(): void; protected onMessageReceived?(e: IpcMessage): void; @@ -258,7 +263,6 @@ export abstract class WebviewViewBase implements ]); const cspSource = webview.cspSource; - const cspNonce = getNonce(); const root = webview.asWebviewUri(this.container.context.extensionUri).toString(); const webRoot = webview.asWebviewUri(webRootUri).toString(); @@ -274,9 +278,9 @@ export abstract class WebviewViewBase implements case 'endOfBody': return `${ bootstrap != null - ? `` + ? `` : '' }${endOfBody ?? ''}`; case 'placement': @@ -284,7 +288,7 @@ export abstract class WebviewViewBase implements case 'cspSource': return cspSource; case 'cspNonce': - return cspNonce; + return this.cspNonce; case 'root': return root; case 'webroot':