__asyncHydrate(el, instance, hydrate) {
if (hydrateStrategy) {
- let teardown: (() => void) | void
- if (resolvedComp) {
- teardown = hydrateStrategy(hydrate, cb => forEachElement(el, cb))
- } else {
- teardown = hydrateStrategy(
- () => performLoad().then(() => !instance.isUnmounted && hydrate()),
- cb => forEachElement(el, cb),
- )
+ const hydrateWithCallback = (postHydrate?: () => void) => {
+ if (resolvedComp) {
+ hydrate()
+ postHydrate && postHydrate()
+ } else {
+ performLoad().then(() => {
+ if (!instance.isUnmounted) {
+ hydrate()
+ postHydrate && postHydrate()
+ }
+ })
+ }
}
+ let teardown = hydrateStrategy(hydrateWithCallback, cb =>
+ forEachElement(el, cb),
+ )
if (teardown) {
;(instance.bum || (instance.bum = [])).push(teardown)
}
* listeners.
*/
export type HydrationStrategy = (
- hydrate: () => void | Promise<any>,
+ hydrate: (postHydrate?: () => void) => void,
forEachElement: (cb: (el: Element) => any) => void,
) => (() => void) | void
export const hydrateOnIdle: HydrationStrategyFactory<number> =
(timeout = 10000) =>
hydrate => {
- const id = requestIdleCallback(hydrate, { timeout })
+ const id = requestIdleCallback(() => hydrate(), { timeout })
return () => cancelIdleCallback(id)
}
if (mql.matches) {
hydrate()
} else {
- mql.addEventListener('change', hydrate, { once: true })
- return () => mql.removeEventListener('change', hydrate)
+ const doHydrate = () => hydrate()
+ mql.addEventListener('change', doHydrate, { once: true })
+ return () => mql.removeEventListener('change', doHydrate)
}
}
}
(hydrate, forEach) => {
if (isString(interactions)) interactions = [interactions]
let hasHydrated = false
- const doHydrate = async (e: Event) => {
+ const doHydrate = (e: Event) => {
if (!hasHydrated) {
hasHydrated = true
teardown()
- // eslint-disable-next-line no-restricted-syntax
- await hydrate()
- // replay event
- e.target!.dispatchEvent(new (e.constructor as any)(e.type, e))
+ hydrate(() => {
+ // replay event
+ e.target!.dispatchEvent(new (e.constructor as any)(e.type, e))
+ })
}
}
const teardown = () => {