Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
78849f3
WIP dialog recording
Juice10 Jun 10, 2024
c1d850f
chore: its important to run `yarn build:all` before running `yarn dev`
Juice10 Jun 10, 2024
b657233
feat: trigger showModal from rrdom and rrweb
Juice10 Jun 10, 2024
337b4c4
feat: Add support for replaying modal and non modal dialog elements
Juice10 Jun 11, 2024
29d4827
chore: Update dev script to remove CLEAR_DIST_DIR flag
Juice10 Jun 11, 2024
dcc867c
Get modal recording and replay working
Juice10 Jun 12, 2024
1144c9d
DRY up dialog test and dedupe snapshot images
Juice10 Jun 12, 2024
7507f4d
Fix eslint error
Juice10 Jun 12, 2024
b8679a0
feat: Refactor dialog test to use updated attribute name
Juice10 Jun 12, 2024
6ec4727
feat: Update dialog test to include rr_open attribute
Juice10 Jun 12, 2024
f7db71c
chore: Add npm dependency [email protected]
Juice10 Jun 12, 2024
b300674
Fix dialog test
Juice10 Jun 12, 2024
178ec1f
Add more test cases for dialog
Juice10 Jun 12, 2024
4229391
Add changesets
Juice10 Jun 12, 2024
b0065ce
Clean up naming
Juice10 Jun 12, 2024
25678f4
Apply formatting changes
Juice10 Jun 12, 2024
b71c8b7
Refactor dialog open code
Juice10 Jun 12, 2024
05d4cf0
Merge branch 'juice10/record-dialog' of https://github.com/rrweb-io/r…
Juice10 Jun 12, 2024
e731636
Revert changed code that doesn't do anything
Juice10 Jun 12, 2024
184e4fa
Add documentation for unimplemented type
Juice10 Jun 12, 2024
6a58edc
chore: Remove unnecessary comments in dialog.test.ts
Juice10 Jun 12, 2024
8c51129
Merge branch 'master' of https://github.com/rrweb-io/rrweb into juice…
Juice10 Jun 26, 2024
0df7994
rename rr_open to rr_openMode
Juice10 Jun 26, 2024
1ce8f70
Replace todo with a skipped test
Juice10 Jun 26, 2024
8aeb47f
Add better logging for CI
Juice10 Jun 26, 2024
985ac9f
Rename rr_openMode to rr_open_mode
Juice10 Jun 26, 2024
d693da9
Remove unused images
Juice10 Jun 26, 2024
760908f
Move after iframe append based on @YunFeng0817's comment
Juice10 Jul 9, 2024
2dfeb01
Remove redundant dialog handling from rrdom.
Juice10 Jul 9, 2024
63c0def
Merge branch 'master' into juice10/record-dialog
Juice10 Jul 9, 2024
21c4826
Rename variables for dialog handling in rrweb replay module
Juice10 Jul 9, 2024
424e4c8
Merge branch 'juice10/record-dialog' of https://github.com/rrweb-io/r…
Juice10 Jul 9, 2024
30c7780
Merge branch 'master' into juice10/record-dialog
eoghanmurray Jul 31, 2024
9f2a27c
Update packages/rrdom/src/document.ts
Juice10 Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clean up naming
  • Loading branch information
Juice10 committed Jun 12, 2024
commit b0065cecbdde30fdb345a41781a9fb20cb4fefbf
20 changes: 11 additions & 9 deletions packages/rrdom/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,22 +550,24 @@ export class BaseRRMediaElement extends BaseRRElement {
export class BaseRRDialogElement extends BaseRRElement {
public readonly tagName = 'DIALOG' as const;
public readonly nodeName = 'DIALOG' as const;
public open = false;
private _isModal = false;

get isModal() {
return this._isModal;
return this.getAttribute('rr_open') === 'modal';
}
get open() {
return this.getAttribute('open') !== null;
}
public close() {
this.open = false;
this._isModal = false;
this.removeAttribute('open');
this.removeAttribute('rr_open');
}
public show() {
this.open = true;
this._isModal = false;
this.setAttribute('open', '');
this.setAttribute('rr_open', 'non-modal');
}
public showModal() {
this.open = true;
this._isModal = true;
this.setAttribute('open', '');
this.setAttribute('rr_open', 'modal');
}
}

Expand Down
27 changes: 20 additions & 7 deletions packages/rrweb/src/replay/dialog/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import type { attributeMutation } from '@rrweb/types';
import { RRNode } from 'rrdom';

export function triggerShowModalForModals(
/**
* Checks if the dialog is a top level dialog and applies the dialog to the top level
* @param node - potential dialog element to apply top level `showModal()` to, or other node (which will be ignored)
* @param attributeMutation - the attribute mutation used to change the dialog (optional)
* @returns void
*/
export function applyDialogToTopLevel(
node: HTMLDialogElement | Node | RRNode,
attributeMutation?: attributeMutation,
) {
): void {
if (node.nodeName !== 'DIALOG' || node instanceof RRNode) return;
const dialog = node as HTMLDialogElement;
const isOpen = dialog.open;
const isModal = isOpen && dialog.matches('dialog:modal');
const rrOpen = dialog.getAttribute('rr_open');

const shouldBeOpen =
typeof attributeMutation?.attributes.open === 'string' ||
typeof dialog.getAttribute('open') === 'string';
const shouldBeModal = dialog.getAttribute('rr_open') === 'modal';
const shouldBeNonModal = dialog.getAttribute('rr_open') === 'non-modal';
const shouldBeModal = rrOpen === 'modal';
const shouldBeNonModal = rrOpen === 'non-modal';

const modeChanged =
(isModal && shouldBeNonModal) || (!isModal && shouldBeModal);

Expand All @@ -26,17 +34,22 @@ export function triggerShowModalForModals(
}

if (isOpen) dialog.close();

if (!shouldBeOpen) return;

if (shouldBeModal) dialog.showModal();
else dialog.show();
}

export function triggerCloseForModals(
/**
* Check if the dialog is a top level dialog and removes the dialog from the top level if necessary
* @param node - potential dialog element to remove from top level, or other node (which will be ignored)
* @param attributeMutation - the attribute mutation used to change the dialog
* @returns void
*/
export function removeDialogFromTopLevel(
node: HTMLDialogElement | Node | RRNode,
attributeMutation: attributeMutation,
) {
): void {
if (node.nodeName !== 'DIALOG' || node instanceof RRNode) return;
const dialog = node as HTMLDialogElement;

Expand Down
25 changes: 13 additions & 12 deletions packages/rrweb/src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import './styles/style.css';
import canvasMutation from './canvas';
import { deserializeArg } from './canvas/deserialize-args';
import { MediaManager } from './media';
import { triggerShowModalForModals, triggerCloseForModals } from './dialog';
import { applyDialogToTopLevel, removeDialogFromTopLevel } from './dialog';

const SKIP_TIME_INTERVAL = 5 * 1000;

Expand Down Expand Up @@ -246,7 +246,7 @@ export class Replayer {
this.applyStyleDeclaration(data, styleSheet);
},
afterAppend: (node: Node, id: number) => {
triggerShowModalForModals(node);
applyDialogToTopLevel(node);
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild) plugin.onBuild(node, { id, replayer: this });
}
Expand Down Expand Up @@ -853,7 +853,7 @@ export class Replayer {
}
const { documentElement, head } = this.iframe.contentDocument;
this.insertStyleRules(documentElement, head);
collectedDialogs.forEach((d) => triggerShowModalForModals(d));
collectedDialogs.forEach((d) => applyDialogToTopLevel(d));
if (!this.service.state.matches('playing')) {
this.iframe.contentDocument
.getElementsByTagName('html')[0]
Expand Down Expand Up @@ -916,10 +916,11 @@ export class Replayer {
type TNode = typeof mirror extends Mirror ? Node : RRNode;
type TMirror = typeof mirror extends Mirror ? Mirror : RRDOMMirror;

const collected: AppendedIframe[] = [];
const collectedIframes: AppendedIframe[] = [];
const collectedDialogs = new Set<HTMLDialogElement>();
const afterAppend = (builtNode: Node, id: number) => {
triggerShowModalForModals(builtNode);
this.collectIframeAndAttachDocument(collected, builtNode);
if (builtNode.nodeName === 'DIALOG') collectedDialogs.add(builtNode as HTMLDialogElement);
this.collectIframeAndAttachDocument(collectedIframes, builtNode);
const sn = (mirror as TMirror).getMeta(builtNode as unknown as TNode);
if (
sn?.type === NodeType.Element &&
Expand Down Expand Up @@ -953,7 +954,8 @@ export class Replayer {
});
afterAppend(iframeEl.contentDocument! as Document, mutation.node.id);

for (const { mutationInQueue, builtNode } of collected) {
collectedDialogs.forEach((d) => applyDialogToTopLevel(d));
for (const { mutationInQueue, builtNode } of collectedIframes) {
this.attachDocumentToIframe(mutationInQueue, builtNode);
this.newDocumentQueue = this.newDocumentQueue.filter(
(m) => m !== mutationInQueue,
Expand Down Expand Up @@ -1539,7 +1541,7 @@ export class Replayer {
const afterAppend = (node: Node | RRNode, id: number) => {
// Skip the plugin onBuild callback for virtual dom
if (this.usingVirtualDom) return;
triggerShowModalForModals(node);
applyDialogToTopLevel(node);
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild) plugin.onBuild(node, { id, replayer: this });
}
Expand Down Expand Up @@ -1743,10 +1745,9 @@ export class Replayer {
if (typeof attributeName === 'string') {
const value = mutation.attributes[attributeName];
if (value === null) {
if (attributeName === 'open') {
triggerCloseForModals(target, mutation);
}
(target as Element | RRElement).removeAttribute(attributeName);
if (attributeName === 'open')
removeDialogFromTopLevel(target, mutation);
} else if (typeof value === 'string') {
try {
// When building snapshot, some link styles haven't loaded. Then they are loaded, they will be inlined as incremental mutation change of attribute. We need to replace the old elements whose styles aren't inlined.
Expand Down Expand Up @@ -1804,7 +1805,7 @@ export class Replayer {
}

if (attributeName === 'rr_open' && target.nodeName === 'DIALOG') {
triggerShowModalForModals(target, mutation);
applyDialogToTopLevel(target, mutation);
}
} catch (error) {
this.warn(
Expand Down