Преглед изворни кода

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

Only use the React compiler when showNewPdfPreview is set

GitOrigin-RevId: 24bf8dc6a830e670ee8dc30b8e0329127de1a1a8
Alf Eaton пре 5 година
родитељ
комит
2bf422b76d

+ 1 - 0
services/web/.storybook/preview.js

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

+ 1 - 0
services/web/app/views/project/editor.pug

@@ -189,6 +189,7 @@ block append meta
 	meta(name="ol-showNewLogsUI" data-type="boolean" content=showNewLogsUI)
 	meta(name="ol-showNewLogsUI" data-type="boolean" content=showNewLogsUI)
 	meta(name="ol-logsUISubvariant" content=logsUISubvariant)
 	meta(name="ol-logsUISubvariant" content=logsUISubvariant)
 	meta(name="ol-showSymbolPalette" data-type="boolean" content=showSymbolPalette)
 	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-enablePdfCaching" data-type="boolean" content=enablePdfCaching)
 	meta(name="ol-trackPdfDownload" data-type="boolean" content=trackPdfDownload)
 	meta(name="ol-trackPdfDownload" data-type="boolean" content=trackPdfDownload)
 	meta(name="ol-resetServiceWorker" data-type="boolean" content=resetServiceWorker)
 	meta(name="ol-resetServiceWorker" data-type="boolean" content=resetServiceWorker)

+ 5 - 0
services/web/frontend/js/features/pdf-preview/util/compiler.js

@@ -51,6 +51,11 @@ export default class DocumentCompiler {
   // The main "compile" function.
   // The main "compile" function.
   // Call this directly to run a compile now, otherwise call debouncedAutoCompile.
   // Call this directly to run a compile now, otherwise call debouncedAutoCompile.
   async compile(options = {}) {
   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
     // set "compiling" to true (in the React component's state), and return if it was already true
     let wasCompiling
     let wasCompiling
 
 

+ 3 - 1
services/web/frontend/js/shared/context/compile-context.js

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

+ 8 - 0
services/web/test/frontend/features/pdf-preview/components/pdf-js-viewer.test.js

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

+ 2 - 0
services/web/test/frontend/features/pdf-preview/components/pdf-preview.test.js

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