(core) Re-render assistant code blocks on theme change

Summary:
When the browser theme transitioned while the assistant was open, messages
containing code blocks were not being re-rendered with the new theme.

Test Plan: Manual.

Reviewers: paulfitz

Reviewed By: paulfitz

Subscribers: paulfitz

Differential Revision: https://phab.getgrist.com/D3965
This commit is contained in:
George Gevoian 2023-07-20 20:28:22 -04:00
parent 391c8ee087
commit 5e26401a24

View File

@ -23,7 +23,7 @@ import {loadingDots} from 'app/client/ui2018/loaders';
import {menu, menuCssClass, menuItem} from 'app/client/ui2018/menus';
import {TelemetryEvent, TelemetryMetadata} from 'app/common/Telemetry';
import {Computed, Disposable, dom, DomElementArg, makeTestId,
MutableObsArray, obsArray, Observable, styled} from 'grainjs';
MutableObsArray, obsArray, Observable, styled, subscribeElem} from 'grainjs';
import debounce from 'lodash/debounce';
import noop from 'lodash/noop';
import {marked} from 'marked';
@ -931,7 +931,7 @@ class ChatHistory extends Disposable {
const doc = this._options.gristDoc;
if (this.supportsMarkdown()) {
return dom('div',
(el) => {
(el) => subscribeElem(el, doc.currentTheme, () => {
const content = sanitizeHTML(marked(message, {
highlight: (code) => {
const codeBlock = buildHighlightedCode(code, {
@ -942,10 +942,9 @@ class ChatHistory extends Disposable {
},
}));
el.innerHTML = content;
},
}),
...args
);
} else {
return buildHighlightedCode(message, {
gristTheme: doc.currentTheme,