Skip to content

Preserve Xmatter music when book is updated (BL-16036)#7777

Open
JohnThomson wants to merge 1 commit intomasterfrom
keepXmatterMusic
Open

Preserve Xmatter music when book is updated (BL-16036)#7777
JohnThomson wants to merge 1 commit intomasterfrom
keepXmatterMusic

Conversation

@JohnThomson
Copy link
Copy Markdown
Contributor

@JohnThomson JohnThomson commented Mar 26, 2026


Open with Devin

This change is Reviewable

devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

@JohnThomson JohnThomson left a comment

Choose a reason for hiding this comment

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

@JohnThomson made 1 comment.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion.

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 3 new potential issues.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment on lines +2590 to +2595
private static readonly HashSet<string> kXmatterPageAttributesToPreserve =
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
HtmlDom.musicAttrName,
HtmlDom.musicVolumeName,
};
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot Mar 26, 2026

Choose a reason for hiding this comment

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

📝 Info: Behavioral narrowing of GatherXmatterPageDataAttributeSetIntoDataSet from catch-all to whitelist

The old code at BookData.cs:1665-1676 gathered ALL data-* attributes (except data-xmatter-page) from xmatter page elements into the dataset. The new code only gathers attributes in _xmatterPageAttributesToPreserveSet (i.e., data-backgroundaudio and data-backgroundaudiovolume). This means any previously-stored non-music data-* attributes in the data-div will be silently dropped on the next update cycle, since PushXmatterPageAttributesIntoDataDiv (BookData.cs:589-609) removes the old data-div element and recreates it with only the filtered attributes. This is almost certainly intentional cleanup, but if any xmatter template introduces a new user-editable data-* attribute in the future, it will need to be added to PageAttributesToSaveAndPreserveInXmatter at HtmlDom.cs:1903 to survive xmatter replacement.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JohnThomson can you comment on this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've attempted to refactor so there is a single source of truth for what page attributes need to be saved and what ones additionally need to survive xmatter update and therefore get copied in BookData

Comment on lines 2582 to 2585
RestoreXmatterPageAttributesToPreserve(bookDOM, xmatterAttributesByPage);

var dataBookLangs = bookDOM.GatherDataBookLanguages();
TranslationGroupManager.PrepareDataBookTranslationGroups(bookDOM.RawDom, dataBookLangs);
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot Mar 26, 2026

Choose a reason for hiding this comment

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

🚩 Data-div priority could mask freshly-restored page attributes in edge cases

In SynchronizeDataItemsThroughoutDOM, the data-div is processed before actual pages (BookData.cs:1389: if (!data.XmatterPageDataAttributeSets.ContainsKey(key))). If the data-div has an xmatter page entry without music attributes (e.g., from a prior save where no music was set), and RestoreXmatterPageAttributesToPreserve just restored music attributes to the actual page, the dataset will have the data-div's empty set and skip the page. However, this doesn't cause data loss because UpdateXmatterPageDataAttributeSets (BookData.cs:2070-2077) only sets attributes from the dataset — it never removes attributes already on the page. So the restored music attributes survive. But on the next save cycle, PushXmatterPageAttributesIntoDataDiv will write an empty set to the data-div, meaning the data-div won't persist the music attributes until the user triggers another edit cycle that reads them from the page first. The new CaptureXmatterPageAttributesToPreserve in Book.cs compensates for this by reading directly from pages rather than relying on the data-div.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JohnThomson can you confirm this is ok?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't clearly understand what it's getting at. The code has changed considerably in response to other comments. It seems to be working.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This and another comment from devin indicate it thinks we now have two overlapping ways of dealing with saving such attributes. The other place calls it a belt-and-suspenders. But given that you thought this couldn't be a regression but Colin says it is, my intuition is that there is more going on here to understand.
In other words, devin seems to think that there is already code which is attempting to do the thing but we now added code to do the thing instead of fixing that code.

Copy link
Copy Markdown
Contributor Author

@JohnThomson JohnThomson left a comment

Choose a reason for hiding this comment

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

@JohnThomson made 3 comments.
Reviewable status: 0 of 4 files reviewed, 2 unresolved discussions (waiting on hatton).

Comment on lines 2582 to 2585
RestoreXmatterPageAttributesToPreserve(bookDOM, xmatterAttributesByPage);

var dataBookLangs = bookDOM.GatherDataBookLanguages();
TranslationGroupManager.PrepareDataBookTranslationGroups(bookDOM.RawDom, dataBookLangs);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't clearly understand what it's getting at. The code has changed considerably in response to other comments. It seems to be working.

Comment on lines +2590 to +2595
private static readonly HashSet<string> kXmatterPageAttributesToPreserve =
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
HtmlDom.musicAttrName,
HtmlDom.musicVolumeName,
};
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've attempted to refactor so there is a single source of truth for what page attributes need to be saved and what ones additionally need to survive xmatter update and therefore get copied in BookData

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants