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

Pause typekit MutationObserver during scrolling #6699

Merged
merged 5 commits into from
Jul 16, 2024
Merged

Conversation

devongovett
Copy link
Member

First commit pauses the TypeKit MutationObserver while Virtualizer is scrolling so that it isn't constantly updating due to DOM nodes being added/removed/reused. After scrolling, it is resumed so that the dynamic subsetting needed for CJK fonts updates properly.

Second commit is a couple other minor performance improvements I noticed while testing it. Mainly keeping object shape the same (rather than adding node later) and breaking out of loop early while building a table row outside the requested rect.

async: true
},
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='https://use-staging.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)
})(document);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using a staging typekit build for testing. Will revert before merging.

@@ -102,6 +102,8 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
state.isScrolling = true;
setScrolling(true);

// Pause typekit MutationObserver during scrolling.
window.dispatchEvent(new Event('tk.disconnect-observer'));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to move this to a Spectrum-only location? We would currently need to copy it into several places in both v3 and s2, and any custom components people build with virtualizer would also need it. Not sure if there's really much harm for it being there outside Adobe too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine keeping it here, like you said I don't think firing this event even for non-spectrum virtualizer experiences is a problem. This event is specific to our typekit right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would affect any typekit even ones used by third parties, which is probably a good thing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, better to have it included for non-spectrum typekits and also non-spectrum virtualizer setups.

We could do a check for a typekit on load, but I don't think it would make much of a difference.

@rspbot
Copy link

rspbot commented Jul 12, 2024

LFDanLu
LFDanLu previously approved these changes Jul 12, 2024
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the performance improvement and didn't notice any problems arising in the TableView/ListBox from the other changes

@@ -102,6 +102,8 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
state.isScrolling = true;
setScrolling(true);

// Pause typekit MutationObserver during scrolling.
window.dispatchEvent(new Event('tk.disconnect-observer'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine keeping it here, like you said I don't think firing this event even for non-spectrum virtualizer experiences is a problem. This event is specific to our typekit right?

reidbarber
reidbarber previously approved these changes Jul 12, 2024
validRect: rect
children: [],
validRect: rect,
node
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update interface LayoutNode to require node and children?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that before but there are some that don't have associated nodes (the loader and empty state in RSP).

@rspbot
Copy link

rspbot commented Jul 15, 2024

@devongovett devongovett dismissed stale reviews from LFDanLu and reidbarber via 5bc4d5c July 16, 2024 03:58
@rspbot
Copy link

rspbot commented Jul 16, 2024

@rspbot
Copy link

rspbot commented Jul 16, 2024

## API Changes

unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }

@devongovett devongovett merged commit 975bf1d into main Jul 16, 2024
28 checks passed
@devongovett devongovett deleted the typekit-perf branch July 16, 2024 16:08
@dannify dannify removed the release label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants