Skip to content

Conversation

arturovt
Copy link
Collaborator

In this commit, we implement lazy loading for tippy.js to avoid loading it until it's actually necessary. Tooltips are commonly used across the app, but they’re not needed until the directive is rendered. However, the tippy.js package is always included in the common bundle. For example, if we have a <button [tp]="..." /> element hidden by a conditional @if (condition) { ... }, tippy.js would load immediately, even if the button isn't in the DOM.

We’ve added a loader property to the config, allowing users to specify a loader function for the Tippy module. This can be () => tippy or () => import('tippy.js'), depending on whether users want to lazy-load it.

This change is breaking because it introduces a required property to the config. However, the migration should be straightforward, as users only need to explicitly add the new property to provideTippyConfig.

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

In this commit, we implement lazy loading for `tippy.js` to avoid loading it until it's actually
necessary. Tooltips are commonly used across the app, but they’re not needed until the directive
is rendered. However, the `tippy.js` package is always included in the common bundle.
For example, if we have a `<button [tp]="..." />` element hidden by a conditional
`@if (condition) { ... }`, `tippy.js` would load immediately, even if the button isn't in the DOM.

We’ve added a `loader` property to the config, allowing users to specify a loader function for
the Tippy module. This can be `() => tippy` or `() => import('tippy.js')`, depending on whether
users want to lazy-load it.

This change is breaking because it introduces a required property to the config.
However, the migration should be straightforward, as users only need to explicitly add
the new property to `provideTippyConfig`.
@arturovt arturovt marked this pull request as ready for review November 13, 2024 16:27
private _tippy$: Observable<typeof tippy> | null = null;

create(target: HTMLElement, props?: Partial<TippyProps>) {
this._tippy$ = defer(() => {
Copy link
Member

Choose a reason for hiding this comment

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

We probably want to do this if !this.tippy$

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah I meant to use ||= ....

@NetanelBasal NetanelBasal merged commit 74a3ed6 into ngneat:master Nov 13, 2024
2 checks passed
@arturovt arturovt deleted the feat/add-loading branch November 13, 2024 19:30
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.

2 participants