File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -70,13 +70,19 @@ function init() {
7070
7171 getAlpineDataInstance ( node ) {
7272 if ( this . isV3 ) {
73- return node . _x_dataStack [ 0 ]
73+ return node . _x_dataStack ?. [ 0 ]
7474 }
7575 return node . __x
7676 }
7777
7878 getReadOnlyAlpineData ( node ) {
7979 const alpineDataInstance = this . getAlpineDataInstance ( node )
80+ if ( ! alpineDataInstance ) {
81+ if ( process . env . NODE_ENV !== 'production' ) {
82+ console . warn ( 'element has no dataStack' , node )
83+ }
84+ return
85+ }
8086 if ( this . isV3 ) {
8187 // in v3 magics are registered on the data stack
8288 return Object . fromEntries ( Object . entries ( alpineDataInstance ) . filter ( ( [ key ] ) => ! key . startsWith ( '$' ) ) )
@@ -276,11 +282,15 @@ function init() {
276282
277283 sendComponentData ( componentId , componentRoot ) {
278284 const componentData = this . getReadOnlyAlpineData ( componentRoot )
285+
286+ if ( ! componentData ) return
287+
279288 const data = Object . entries ( componentData ) . reduce ( ( acc , [ key , value ] ) => {
280289 acc [ key ] = serializeDataProperty ( value )
281290
282291 return acc
283292 } , { } )
293+
284294 this . _postMessage ( {
285295 type : BACKEND_TO_PANEL_MESSAGES . SET_DATA ,
286296 componentId,
Original file line number Diff line number Diff line change 121121 < div >
122122 < a data-testid ="navigation-target " href ="/navigation-target.html "> Go to next page</ a >
123123 </ div >
124+
125+ < h3 > Manual test</ h3 >
126+ < p >
127+ Can't reproduce
128+ < a href ="https://github.com/alpinejs/alpine/discussions/1952 "
129+ > https://github.com/alpinejs/alpine/discussions/1952</ a
130+ >
131+ </ p >
132+ < div x-data @focus-input.window ="$refs.searchInput.focus() ">
133+ < input x-ref ="searchInput " />
134+ </ div >
135+ < button onclick ="document.dispatchEvent(new CustomEvent('focus-input')) "> Click</ button >
124136 </ body >
125137</ html >
You can’t perform that action at this time.
0 commit comments