@@ -9,7 +9,6 @@ const createAwaitableMutationObserver = (
9
9
10
10
return ( options : { selector : string ; root ?: HTMLElement | null ; timeout ?: number } ) =>
11
11
new Promise < void > ( ( resolve , reject ) => {
12
- console . log ( 'Selector' , options . selector ) ;
13
12
const { root = document ?. body , selector, timeout = 0 } = options ;
14
13
15
14
if ( ! root ) {
@@ -31,19 +30,15 @@ const createAwaitableMutationObserver = (
31
30
// Set up a MutationObserver to detect when the element has children
32
31
const observer = new MutationObserver ( mutationsList => {
33
32
for ( const mutation of mutationsList ) {
34
- console . log ( 'Mutation' , mutation ) ;
35
33
if ( ! elementToWatch && selector ) {
36
34
elementToWatch = root ?. querySelector ( selector ) ;
37
35
}
38
- console . log ( 'elementToWatch' , elementToWatch ) ;
39
36
40
37
if (
41
38
( globalOptions . childList && mutation . type === 'childList' ) ||
42
39
( globalOptions . attributes && mutation . type === 'attributes' )
43
40
) {
44
- console . log ( 'isReady' , isReady ( elementToWatch , selector ) ) ;
45
41
if ( isReady ( elementToWatch , selector ) ) {
46
- console . log ( 'disconnecting' ) ;
47
42
observer . disconnect ( ) ;
48
43
resolve ( ) ;
49
44
return ;
@@ -67,17 +62,17 @@ const createAwaitableMutationObserver = (
67
62
const waitForElementChildren = createAwaitableMutationObserver ( {
68
63
childList : true ,
69
64
subtree : true ,
70
- isReady : ( el : HTMLElement | null ) => ! ! el ?. childElementCount && el . childElementCount > 0 ,
65
+ isReady : ( el , selector ) => ! ! el ?. childElementCount && el ?. matches ?. ( selector ) && el . childElementCount > 0 ,
71
66
} ) ;
72
67
73
- const waitForElementAttribute = createAwaitableMutationObserver ( {
74
- attributes : true ,
75
- // childList: true,
76
- // subtree: true,
77
- isReady : ( el : HTMLElement | null , selector : string ) => {
78
- return el ?. matches ?.( selector ) ?? false ;
79
- } ,
80
- } ) ;
68
+ // const waitForElementAttribute = createAwaitableMutationObserver({
69
+ // attributes: true,
70
+ // // childList: true,
71
+ // // subtree: true,
72
+ // isReady: (el: HTMLElement | null, selector: string) => {
73
+ // return el?.matches?.(selector) ?? false;
74
+ // },
75
+ // });
81
76
82
77
/**
83
78
* Detect when a Clerk component has mounted by watching DOM updates to an element with a `data-clerk-component="${component}"` property.
@@ -98,11 +93,12 @@ export function useWaitForComponentMount(
98
93
const selector = `[data-clerk-component="${ component } "]` ;
99
94
const attributeSelector = options ?. selector ;
100
95
console . log ( 'attributeSelector' , attributeSelector , attributeSelector + selector ) ;
101
- watcherRef . current = (
102
- attributeSelector
103
- ? waitForElementAttribute ( { selector : attributeSelector + selector } )
104
- : waitForElementChildren ( { selector } )
105
- )
96
+ watcherRef . current = waitForElementChildren ( {
97
+ selector : attributeSelector ? attributeSelector + selector : selector ,
98
+ } )
99
+ // .then(res => {
100
+ // return attributeSelector ? waitForElementAttribute({ selector: attributeSelector + selector }) : res;
101
+ // })
106
102
. then ( ( ) => {
107
103
console . log ( 'rendered' , component ) ;
108
104
setStatus ( 'rendered' ) ;
0 commit comments