Skip to content

Commit

Permalink
Avoids needless re-renders
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 17, 2022
1 parent d10e76b commit 6187d28
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/webviews/webviewViewBase.ts
Expand Up @@ -91,6 +91,11 @@ export abstract class WebviewViewBase<State, SerializedState = State> implements
}
}

private readonly _cspNonce = getNonce();
protected get cspNonce(): string {
return this._cspNonce;
}

protected onInitializing?(): Disposable[] | undefined;
protected onReady?(): void;
protected onMessageReceived?(e: IpcMessage): void;
Expand Down Expand Up @@ -258,7 +263,6 @@ export abstract class WebviewViewBase<State, SerializedState = State> implements
]);

const cspSource = webview.cspSource;
const cspNonce = getNonce();

const root = webview.asWebviewUri(this.container.context.extensionUri).toString();
const webRoot = webview.asWebviewUri(webRootUri).toString();
Expand All @@ -274,17 +278,17 @@ export abstract class WebviewViewBase<State, SerializedState = State> implements
case 'endOfBody':
return `${
bootstrap != null
? `<script type="text/javascript" nonce="${cspNonce}">window.bootstrap=${JSON.stringify(
bootstrap,
)};</script>`
? `<script type="text/javascript" nonce="${
this.cspNonce
}">window.bootstrap=${JSON.stringify(bootstrap)};</script>`
: ''
}${endOfBody ?? ''}`;
case 'placement':
return 'view';
case 'cspSource':
return cspSource;
case 'cspNonce':
return cspNonce;
return this.cspNonce;
case 'root':
return root;
case 'webroot':
Expand Down

0 comments on commit 6187d28

Please sign in to comment.