-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix inline link elements bug #995
Conversation
7e7f5a6
to
23addd0
Compare
texts: [], | ||
attributes: [], | ||
}); | ||
if ('_cssText' in (childSn as elementNode).attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is _cssText
always going to be set, also if a link element hasn't finished loading yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According the code below
rrweb/packages/rrweb-snapshot/src/snapshot.ts
Lines 653 to 659 in 08ab7ab
if (stylesheet) { | |
cssText = getCssRulesString(stylesheet); | |
} | |
if (cssText) { | |
delete attributes.rel; | |
delete attributes.href; | |
attributes._cssText = absoluteToStylesheet(cssText, stylesheet!.href!); |
I think it will set _cssText when the link has been loaded. Otherwise, recorder will only keep its original attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for finding and fixing this bug! I found a one bug and maybe another potential bug. Could you fix those and I'd be happy to re-review & approve!
8e74045
to
6bde25a
Compare
6bde25a
to
d311687
Compare
1. make Mirror's replace function act the same with the original one when there's no existed node to get replaced. 2. when replacing with the link/style elements, keep their existing attributes to prevent potential bugs
d311687
to
8aefe2b
Compare
I rebased the latest master branch and this pull request is ready to get reviewed and merged. |
In PR #909, an async mechanism for inlining link elements is introduced but it still has a bug and some negative impacts on the replayer side.
The Bug
In the stylesheet-manager.ts, when the link element loaded the styles, the manager emits an incremental mutation event to inline styles. But the mutation's parentId is wrong.
rrweb/packages/rrweb/src/record/stylesheet-manager.ts
Line 34 in abc035f
As a result, the event looks like this:
The parentNode of the link element is itself and it can't be appended to the dom actually.
Negative Impacts
This mechanism makes elements absent in the normal snapshot stage and causes performance issues and many warnings in the console.
Here's a diagram to explain this problem.
Changes
I built this PR based on #989 so that it contains all changes of that PR. This PR has to get merged after #989.
I made some changes to the current mechanism. In the snapshot stage, the unloaded Link elements will still get serialized without inline styles. After they are loaded. an incremental mutation of attributes is appended which includes an attribute
_cssText
. Its value is the inlined CSS styles.This way, the unloaded Link elements can be inlined without causing the above-mentioned side effects.
On the replaying side, when the replayer encounters the '_cssText' attribute change and its target is the Link element, the replayer can replace the old un-inlined one with the inlined loaded Link element.
This method can make it easy to implement the TODO feature as well.
rrweb/packages/rrweb/src/record/stylesheet-manager.ts
Lines 19 to 24 in abc035f
This PR can also fix #981.