Only record error log deltas for the same rootDocId (#19251)

GitOrigin-RevId: acc05831701e3be0cc0bc96ed0bd495e7cb6745c
This commit is contained in:
Alf Eaton 2024-07-04 11:04:32 +01:00 committed by Copybot
parent 4fe66c0189
commit a587d63f15

View file

@ -355,7 +355,10 @@ export const LocalCompileProvider: FC = ({ children }) => {
// compare log entry counts with the previous compile, and record actions between compiles // 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 // these are refs rather than state so they don't trigger the effect to run
const previousRuleCountsRef = useRef<Record<string, number> | null>(null) const previousRuleCountsRef = useRef<{
ruleCounts: Record<string, number>
rootDocId: string
} | null>(null)
const recordedActionsRef = useRef<Record<string, boolean>>({}) const recordedActionsRef = useRef<Record<string, boolean>>({})
const recordAction = useCallback((action: string) => { const recordAction = useCallback((action: string) => {
recordedActionsRef.current[action] = true recordedActionsRef.current[action] = true
@ -431,18 +434,23 @@ export const LocalCompileProvider: FC = ({ children }) => {
result.logEntries.all result.logEntries.all
) as Record<string, number> ) as Record<string, number>
const previousRuleCounts = previousRuleCountsRef.current const rootDocId = data.rootDocId || compiler.projectRootDocId
previousRuleCountsRef.current = ruleCounts
const ruleDeltas = previousRuleCounts const previousRuleCounts = previousRuleCountsRef.current
? buildRuleDeltas(ruleCounts, previousRuleCounts) previousRuleCountsRef.current = { ruleCounts, rootDocId }
: {}
const ruleDeltas =
previousRuleCounts &&
previousRuleCounts.rootDocId === rootDocId
? buildRuleDeltas(ruleCounts, previousRuleCounts.ruleCounts)
: {}
sendMB('compile-log-entries', { sendMB('compile-log-entries', {
status: data.status, status: data.status,
stopOnFirstError: data.options.stopOnFirstError, stopOnFirstError: data.options.stopOnFirstError,
isAutoCompileOnLoad: !!data.options.isAutoCompileOnLoad, isAutoCompileOnLoad: !!data.options.isAutoCompileOnLoad,
isAutoCompileOnChange: !!data.options.isAutoCompileOnChange, isAutoCompileOnChange: !!data.options.isAutoCompileOnChange,
rootDocId,
...recordedActions, ...recordedActions,
...ruleCounts, ...ruleCounts,
...ruleDeltas, ...ruleDeltas,
@ -529,6 +537,7 @@ export const LocalCompileProvider: FC = ({ children }) => {
setLogEntries, setLogEntries,
setLogEntryAnnotations, setLogEntryAnnotations,
setPdfFile, setPdfFile,
compiler,
]) ])
// switch to logs if there's an error // switch to logs if there's an error