diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d9320cbe2e95..0b5e8dd92f318 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ All notable changes to Sourcegraph are documented in this file. - Fixed an issue with `sourcegraph/server` Docker deployments where syntax highlighting could produce `server closed idle connection` errors. [#4269](https://github.com/sourcegraph/sourcegraph/issues/4269) - Repositories containing submodules not on Sourcegraph will now load without error [#2947](https://github.com/sourcegraph/sourcegraph/issues/2947) - HTTP metrics in Prometheus/Grafana now distinguish between different types of GraphQL requests. +- Fixed an issue where syntax highlighting taking too long would result in errors or wait long amounts of time without properly falling back to plaintext rendering after a few seconds. [#4267](https://github.com/sourcegraph/sourcegraph/issues/4267) [#4268](https://github.com/sourcegraph/sourcegraph/issues/4268) ## 3.4.2 diff --git a/shared/src/components/CodeExcerpt.test.tsx b/shared/src/components/CodeExcerpt.test.tsx index bccd98d856a63..c498a74bbcf31 100644 --- a/shared/src/components/CodeExcerpt.test.tsx +++ b/shared/src/components/CodeExcerpt.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react' import _VisibilitySensor from 'react-visibility-sensor' +import sinon from 'sinon' export class MockVisibilitySensor extends React.Component<{ onChange?: (isVisible: boolean) => void }> { constructor(props: { onChange?: (isVisible: boolean) => void }) { super(props) @@ -23,7 +24,9 @@ jest.mock( ) import { cleanup, getAllByText, getByText, render } from 'react-testing-library' +import { of } from 'rxjs' import { + HIGHLIGHTED_FILE_LINES, HIGHLIGHTED_FILE_LINES_REQUEST, HIGHLIGHTED_FILE_LINES_SIMPLE_REQUEST, } from '../../../web/src/search/testHelpers' @@ -104,4 +107,24 @@ describe('CodeExcerpt', () => { expect(span.textContent === 'test') } }) + + it('does not disable the highlighting timeout', () => { + /* + Because disabling the timeout should only ever be done in response + to the user asking us to do so, something that we do not do for + code excerpts because falling back to plaintext rendering is most + ideal. + */ + const fetchHighlightedFileLines = sinon.spy(ctx => of(HIGHLIGHTED_FILE_LINES)) + const highlightRange = [{ line: 12, character: 7, highlightLength: 4 }] + render( + + ) + sinon.assert.calledOnce(fetchHighlightedFileLines) + sinon.assert.calledWithMatch(fetchHighlightedFileLines, { disableTimeout: false }) + }) }) diff --git a/shared/src/components/CodeExcerpt.tsx b/shared/src/components/CodeExcerpt.tsx index b9c23d51a684f..5fb076284f4c9 100644 --- a/shared/src/components/CodeExcerpt.tsx +++ b/shared/src/components/CodeExcerpt.tsx @@ -66,7 +66,7 @@ export class CodeExcerpt extends React.PureComponent { commitID, filePath, isLightTheme, - disableTimeout: true, + disableTimeout: false, }) ), catchError(error => [asError(error)]) diff --git a/web/src/repo/backend.tsx b/web/src/repo/backend.tsx index 55314eb5a4606..6802227ce222d 100644 --- a/web/src/repo/backend.tsx +++ b/web/src/repo/backend.tsx @@ -218,9 +218,6 @@ export const fetchHighlightedFileLines = memoizeObservable( if (result.isDirectory) { return [] } - if (result.highlightedFile.aborted) { - throw new Error('aborted fetching highlighted contents') - } let parsed = result.highlightedFile.html.substr(''.length) parsed = parsed.substr(0, parsed.length - '
'.length) const rows = parsed.split('')