Skip to content

Commit 1e33fe4

Browse files
committed
Fix bug in repeated collapse of empty bodies
The initial rendering of the empty body wrote '' to the format cache, and observes it. The second rendering reads from the cache, but then because the value is falsey it writes to the cache again! This write side-effect in a computed on an observable is bad bad bad and breaks the rendering. We now properly distinguish cache presence, not just falsey-ness.
1 parent 7ecda0e commit 1e33fe4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/components/editor/content-viewer.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,16 @@ export class ContentViewer extends React.Component<ContentViewerProps> {
142142

143143
const { cache } = this.props;
144144
const cacheKey = this.formatter.cacheKey;
145-
const cachedValue = cache.get(cacheKey) as ObservablePromise<string> | string | undefined;
145+
const hasCachedValue = cache.has(cacheKey);
146146

147-
const renderingContent = cachedValue ||
148-
this.formatter.render(this.contentBuffer, this.props.headers) as ObservablePromise<string> | string;
149-
if (!cachedValue) cache.set(cacheKey, renderingContent);
147+
let renderingContent: string | ObservablePromise<string>;
148+
if (hasCachedValue) {
149+
const cachedValue = cache.get(cacheKey) as ObservablePromise<string> | string;
150+
renderingContent = cachedValue;
151+
} else {
152+
renderingContent = this.formatter.render(this.contentBuffer, this.props.headers) as ObservablePromise<string> | string;
153+
cache.set(cacheKey, renderingContent);
154+
}
150155

151156
if (typeof renderingContent === 'string') {
152157
return renderingContent;

0 commit comments

Comments
 (0)