Skip to content

Commit

Permalink
Merge pull request #598 from microsoft/swradhak/mutationthrottleconfig
Browse files Browse the repository at this point in the history
add a config for disabling mutation throttle
  • Loading branch information
swaathee committed May 12, 2024
2 parents 5257770 + 3458ae2 commit b16b958
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/clarity-js/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ let config: Config = {
upgrade: null,
action: null,
dob: null,
delayDom: false
delayDom: false,
throttleDom: true
};

export default config;
3 changes: 2 additions & 1 deletion packages/clarity-js/src/layout/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import encode from "@src/layout/encode";
import * as region from "@src/layout/region";
import traverse from "@src/layout/traverse";
import processNode from "./node";
import config from "@src/core/config";

let observers: MutationObserver[] = [];
let mutations: MutationQueue[] = [];
Expand Down Expand Up @@ -129,7 +130,7 @@ async function process(): Promise<void> {
if (state === Task.Wait) { state = await task.suspend(timer); }
if (state === Task.Stop) { break; }
let target = mutation.target;
let type = track(mutation, timer, instance, record.time);
let type = config.throttleDom ? track(mutation, timer, instance, record.time) : mutation.type;
if (type && target && target.ownerDocument) { dom.parse(target.ownerDocument); }
if (type && target && target.nodeType == Node.DOCUMENT_FRAGMENT_NODE && (target as ShadowRoot).host) { dom.parse(target as ShadowRoot); }
switch (type) {
Expand Down
1 change: 1 addition & 0 deletions packages/clarity-js/types/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export interface Config {
action?: (key: string) => void;
dob?: number;
delayDom?: boolean;
throttleDom?: boolean;
}

export const enum Constant {
Expand Down

0 comments on commit b16b958

Please sign in to comment.