Skip to content

fix: harden upgrade-to-collaboration rollback state restoration#2510

Closed
harbournick wants to merge 1 commit intomainfrom
nick/collab-upgrade-fixes2
Closed

fix: harden upgrade-to-collaboration rollback state restoration#2510
harbournick wants to merge 1 commit intomainfrom
nick/collab-upgrade-fixes2

Conversation

@harbournick
Copy link
Collaborator

No description provided.

@github-actions
Copy link
Contributor

Status: FAIL

The numbering-part changes look correct — w:abstractNumId and w:numId are the right attribute names per §17.9.1/§17.9.15, and the element names w:abstractNum / w:num are spec-compliant. The restructuring in rebuildDerivedCaches() and #restoreRollbackDocumentState is clean and doesn't introduce any OOXML issues.

However, there's one spec violation surfaced by the new export of getThemeColorPalette:


a:sysClr/@val used as a hex color — docxImporter.js:1191

const colorValue = valueNode?.attributes?.val || valueNode?.attributes?.lastClr;

For a:sysClr, val is type ST_SystemColorVal — a symbolic system color name like "windowText" or "window", not a hex string. Per §20.1.2.3.33, lastClr (type ST_HexColorRGB) is the resolved hex fallback that applications should use when system colors aren't supported. By preferring val first, this code stores #WINDOWTEXT or #WINDOW for the dk1/lt1 scheme slots (which are almost always a:sysClr in real documents), instead of the actual hex.

The fix is to check the element name and use lastClr for a:sysClr, val for a:srgbClr:

const valueNode = colorNode.elements?.find((el) => el.name === 'a:srgbClr' || el.name === 'a:sysClr');
const colorValue =
  valueNode?.name === 'a:sysClr'
    ? valueNode?.attributes?.lastClr
    : valueNode?.attributes?.val;

See https://ooxml.dev/spec?q=sysClr for the attribute definitions.


This bug predates the PR, but since getThemeColorPalette is being newly exported and wired into the rollback restore path, it's worth fixing now rather than propagating into production with more surface area.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5de625550f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 872 to +873
editor.converter.convertedXml = convertedXml;
editor.converter.rebuildDerivedCaches();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Re-render the rollback runtime after patching converter state

#restoreRollbackDocumentState() runs only after #startRuntimeAndWaitForVisualReady() has already mounted and painted the rollback editor. Reassigning convertedXml and rebuilding the derived caches here does not emit any of the editor events that PresentationEditor listens to for rerenders (update, pageStyleUpdate, stylesDefaultsChanged, etc.), so on a failed collaboration upgrade the first revealed rollback view can still be laid out from the stale re-imported styles/numbering/theme data until the user makes another edit. Restoring this state needs to happen before the visual-ready wait completes, or this path needs to trigger a rerender explicitly.

Useful? React with 👍 / 👎.

Comment on lines 871 to +873
if (editor.converter && convertedXml) {
editor.converter.convertedXml = convertedXml;
editor.converter.rebuildDerivedCaches();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore pageStyles when rebuilding rollback-only state

This helper now restores OOXML parts, but it still never restores converter.pageStyles, even though page-setup commands mutate that object directly (setSectionPageMarginsAtSelection) and both renderers read it directly for page size/margins. If a user changes margins, orientation, columns, or alternate headers before upgradeToCollaboration() fails, the rollback runtime keeps the freshly re-imported pageStyles instead of the edited ones, so layout and subsequent exports continue using the wrong page setup despite convertedXml having been restored.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant