From a587d63f15b1835478162e769ed84d28a317519c Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Thu, 4 Jul 2024 11:04:32 +0100 Subject: [PATCH] Only record error log deltas for the same rootDocId (#19251) GitOrigin-RevId: acc05831701e3be0cc0bc96ed0bd495e7cb6745c --- .../shared/context/local-compile-context.tsx | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/services/web/frontend/js/shared/context/local-compile-context.tsx b/services/web/frontend/js/shared/context/local-compile-context.tsx index 77dd2dc6a7..b09fe07f86 100644 --- a/services/web/frontend/js/shared/context/local-compile-context.tsx +++ b/services/web/frontend/js/shared/context/local-compile-context.tsx @@ -355,7 +355,10 @@ export const LocalCompileProvider: FC = ({ children }) => { // compare log entry counts with the previous compile, and record actions between compiles // these are refs rather than state so they don't trigger the effect to run - const previousRuleCountsRef = useRef | null>(null) + const previousRuleCountsRef = useRef<{ + ruleCounts: Record + rootDocId: string + } | null>(null) const recordedActionsRef = useRef>({}) const recordAction = useCallback((action: string) => { recordedActionsRef.current[action] = true @@ -431,18 +434,23 @@ export const LocalCompileProvider: FC = ({ children }) => { result.logEntries.all ) as Record - const previousRuleCounts = previousRuleCountsRef.current - previousRuleCountsRef.current = ruleCounts + const rootDocId = data.rootDocId || compiler.projectRootDocId - const ruleDeltas = previousRuleCounts - ? buildRuleDeltas(ruleCounts, previousRuleCounts) - : {} + const previousRuleCounts = previousRuleCountsRef.current + previousRuleCountsRef.current = { ruleCounts, rootDocId } + + const ruleDeltas = + previousRuleCounts && + previousRuleCounts.rootDocId === rootDocId + ? buildRuleDeltas(ruleCounts, previousRuleCounts.ruleCounts) + : {} sendMB('compile-log-entries', { status: data.status, stopOnFirstError: data.options.stopOnFirstError, isAutoCompileOnLoad: !!data.options.isAutoCompileOnLoad, isAutoCompileOnChange: !!data.options.isAutoCompileOnChange, + rootDocId, ...recordedActions, ...ruleCounts, ...ruleDeltas, @@ -529,6 +537,7 @@ export const LocalCompileProvider: FC = ({ children }) => { setLogEntries, setLogEntryAnnotations, setPdfFile, + compiler, ]) // switch to logs if there's an error