Merge pull request #5522 from overleaf/ae-compile-feature-flag

Only use the React compiler when showNewPdfPreview is set

GitOrigin-RevId: 24bf8dc6a830e670ee8dc30b8e0329127de1a1a8
This commit is contained in:
Alf Eaton 2021-10-21 09:10:25 +01:00 committed by Copybot
parent dd5bcd6098
commit 2bf422b76d
6 changed files with 20 additions and 1 deletions

View file

@ -128,3 +128,4 @@ window.user = {
}
window.project_id = 'storybook-project'
window.showNewPdfPreview = true

View file

@ -189,6 +189,7 @@ block append meta
meta(name="ol-showNewLogsUI" data-type="boolean" content=showNewLogsUI)
meta(name="ol-logsUISubvariant" content=logsUISubvariant)
meta(name="ol-showSymbolPalette" data-type="boolean" content=showSymbolPalette)
meta(name="ol-showNewPdfPreview" data-type="boolean" content=showNewPdfPreview)
meta(name="ol-enablePdfCaching" data-type="boolean" content=enablePdfCaching)
meta(name="ol-trackPdfDownload" data-type="boolean" content=trackPdfDownload)
meta(name="ol-resetServiceWorker" data-type="boolean" content=resetServiceWorker)

View file

@ -51,6 +51,11 @@ export default class DocumentCompiler {
// The main "compile" function.
// Call this directly to run a compile now, otherwise call debouncedAutoCompile.
async compile(options = {}) {
// only compile if the feature flag is enabled
if (!window.showNewPdfPreview) {
return
}
// set "compiling" to true (in the React component's state), and return if it was already true
let wasCompiling

View file

@ -172,7 +172,9 @@ export function CompileProvider({ children }) {
// pass the "uncompiled" value up into the scope for use outside this context provider
useEffect(() => {
setUncompiled(changedAt > 0)
if (window.showNewPdfPreview) {
setUncompiled(changedAt > 0)
}
}, [setUncompiled, changedAt])
// record changes to the autocompile setting

View file

@ -10,6 +10,14 @@ const example = pathToFileURL(
).toString()
describe('<PdfJSViewer/>', function () {
beforeEach(function () {
window.showNewPdfPreview = true
})
afterEach(function () {
window.showNewPdfPreview = undefined
})
it('loads all PDF pages', async function () {
renderWithEditorContext(<PdfJsViewer url={example} />)

View file

@ -149,6 +149,7 @@ describe('<PdfPreview/>', function () {
var clock
beforeEach(function () {
window.showNewPdfPreview = true
clock = sinon.useFakeTimers({
shouldAdvanceTime: true,
now: Date.now(),
@ -157,6 +158,7 @@ describe('<PdfPreview/>', function () {
})
afterEach(function () {
window.showNewPdfPreview = undefined
clock.runAll()
clock.restore()
fetchMock.reset()