Skip to content
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

add a config for disabling mutation throttle #598

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading