-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: duplicate textContent for style element cause incremental style mutation invalid #1417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
4272390
0c90863
8c5a69f
c294538
5d18b46
8825d53
3e00f09
a83dc52
9331f17
226bd9b
9256f7e
55dbb38
71245d7
d1fba35
1e8a670
5211578
d778c77
2a91f6f
02a50bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "rrweb-snapshot": patch | ||
| "rrweb": patch | ||
| --- | ||
|
|
||
| fix: duplicate textContent for style element cause incremental style mutation invalid | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1568,20 +1568,39 @@ export class Replayer { | |
| if ( | ||
| parentSn && | ||
| parentSn.type === NodeType.Element && | ||
| parentSn.tagName === 'textarea' && | ||
| mutation.node.type === NodeType.Text | ||
eoghanmurray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) { | ||
| const childNodeArray = Array.isArray(parent.childNodes) | ||
eoghanmurray marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ? parent.childNodes | ||
| : Array.from(parent.childNodes); | ||
| // This should be redundant now as we are either recording the value or the childNode, and not both | ||
| // keeping around for backwards compatibility with old bad double data, see | ||
|
|
||
| // https://github.com/rrweb-io/rrweb/issues/745 | ||
| // parent is textarea, will only keep one child node as the value | ||
| for (const c of childNodeArray) { | ||
| if (c.nodeType === parent.TEXT_NODE) { | ||
| parent.removeChild(c as Node & RRNode); | ||
| if (parentSn.tagName === 'textarea') { | ||
| // This should be redundant now as we are either recording the value or the childNode, and not both | ||
| // keeping around for backwards compatibility with old bad double data, see | ||
|
|
||
| // https://github.com/rrweb-io/rrweb/issues/745 | ||
| // parent is textarea, will only keep one child node as the value | ||
| for (const c of childNodeArray) { | ||
| if (c.nodeType === parent.TEXT_NODE) { | ||
| parent.removeChild(c as Node & RRNode); | ||
| } | ||
| } | ||
| } else if ( | ||
| parentSn.tagName === 'style' && | ||
| childNodeArray.length === 1 | ||
| ) { | ||
| // https://github.com/rrweb-io/rrweb/pull/1417 | ||
| /** | ||
| * If both _cssText and textContent are present for a style element due to some exist bugs, the element will have two child text nodes. | ||
YunFeng0817 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * We need to remove the textNode created by _cssText to avoid issue. | ||
eoghanmurray marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| for (const cssText of childNodeArray as (Node & RRNode)[]) { | ||
|
||
| if ( | ||
| cssText.nodeType === parent.TEXT_NODE && | ||
| !mirror.hasNode(cssText) | ||
| ) { | ||
| target.textContent = cssText.textContent; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this always going to be the same?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should raise a warning instead in case these are not the same?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be the same, but I’m not entirely sure if there might be any corner cases that could cause issues. I believe that _cssText should always contain the most accurate style content, so I use that value to avoid any potential problems.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tweaked the color in d778c77 to show which one we intend to use. |
||
| parent.removeChild(cssText); | ||
| } | ||
| } | ||
| } | ||
| } else if (parentSn?.type === NodeType.Document) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.