Skip to content

bug(engine-formula): other formula embedded array refs leak into worksheet snapshot #6984

Description

@OTime-Coder

Problem

When array formula snapshot writing is enabled, formulas registered by non-worksheet features such as conditional formatting can record embedded array refs as worksheet cell metadata.

This can pollute workbook snapshot cellData with refs that do not belong to normal worksheet cell formulas. In downstream xlsx export paths, this was observed as worksheet sheetData being exported without cell nodes after import/export roundtrip.

Related discovery issue: dream-num/univer-cli#320.

Concrete Example

A workbook has a conditional formatting rule applied to B1:B5 with a custom formula like:

=IF(A1:A5, "open")

That formula can return an array result while the condition is evaluated for the formatting rule. It is not a worksheet cell formula; it is registered by conditional formatting as an other formula and its value should be consumed by conditional formatting through unitOtherData.

With writeArrayFormulaToSnapshot: true, the array result can currently call setUnitArrayFormulaEmbeddedMap(). Because the runtime does not know the current formula source, the conditional-formatting formula can be recorded as worksheet embedded array-ref metadata, even though no real worksheet cell formula owns that ref.

Root Cause

Formula values are already separated by source:

  • normal worksheet formulas write worksheet runtime data
  • other formulas write unitOtherData
  • feature formulas write feature runtime data

However, embedded array refs were collected from AST execution through FormulaRuntimeService without checking the current formula source. Conditional formatting formulas are registered as other formulas, but their array results could still call setUnitArrayFormulaEmbeddedMap and enter worksheet-only array formula metadata.

Expected Behavior

Embedded array refs should only be collected for normal worksheet cell formulas. Other formula and feature formula results should remain in their corresponding runtime data paths and must not write worksheet array formula metadata.

Fix Direction

Track the current FormulaDependencyTreeType in FormulaRuntimeService and only collect embedded array refs when the current formula type is NORMAL_FORMULA.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions