Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Event listeners throwing exception #189

Closed
chandrin94 opened this issue Apr 8, 2021 · 9 comments
Closed

Event listeners throwing exception #189

chandrin94 opened this issue Apr 8, 2021 · 9 comments
Labels

Comments

@chandrin94
Copy link
Contributor

Describe the bug
Hello,

i noticed that trying to add an event listener to an element results in an IllegalStateException exception being thrown.

To Reproduce
Just create an element, add an event listener to it and navigate to the page where the element exists, e.g :

button(fomantic.ui.blue.button).apply {
    text("Test")
    on.click { 
       println("Test")
    }
}

Expected behavior
The event listener should be added to the element without any exception being thrown.

Actual behavior
An exception with the following stackTrace is thrown:

java.lang.IllegalStateException: fromJson(json, typeToken<T>()) must not be null
	at kweb.html.events.OnReceiver$keydown$$inlined$event$1.invoke(OnReceiver.kt:164)
	at kweb.html.events.OnReceiver$keydown$$inlined$event$1.invoke(OnReceiver.kt:14)
	at kweb.html.events.OnReceiver$event$1.invoke(OnReceiver.kt:18)
	at kweb.html.events.OnReceiver$event$1.invoke(OnReceiver.kt:14)
	at kweb.Element$addEventListener$1.invoke(Element.kt:368)
	at kweb.Element$addEventListener$1.invoke(Element.kt:20)
	at kweb.Kweb.listenForWebsocketConnection(Kweb.kt:306)
	at kweb.Kweb$listenForWebsocketConnection$1.invokeSuspend(Kweb.kt)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
	at java.base/java.lang.Thread.run(Thread.java:829)
@sanity sanity added the bug label Apr 8, 2021
@sanity
Copy link
Member

sanity commented Apr 8, 2021

Hi, thanks for the bug report. Could you confirm the version of Kweb you're seeing this with?

@chandrin94
Copy link
Contributor Author

Hi, thanks for the bug report. Could you confirm the version of Kweb you're seeing this with?

Sure, version 0.8.9

@sanity
Copy link
Member

sanity commented May 14, 2021

@chandrin94 Would you mind checking whether this is still an issue in 0.9.0 which we just released? Much of this code has been rewritten due to migrating from Gson to Kotlin Serialization.

@chandrin94
Copy link
Contributor Author

@chandrin94 Would you mind checking whether this is still an issue in 0.9.0 which we just released? Much of this code has been rewritten due to migrating from Gson to Kotlin Serialization.

@sanity I checked the new version, but it seems i am unable to execute javascript code using callJsFunction. It seems nothing happens when i call this function. Not sure if this is a bug or something changed since version 0.8.9 and i failed to implement the changes. However, in version 0.8.9, i could use the callJsFunction just fine.

@sanity
Copy link
Member

sanity commented May 16, 2021

@chandrin94 hmm, that's not good - may I ask how you're calling callJsFunction(), and how it seems it isn't working? It's used all over Kweb internally so if it wasn't working at all then almost nothing would work.

@sanity
Copy link
Member

sanity commented May 17, 2021

Hey @chandrin94, just wanted to check in on this.

@chandrin94
Copy link
Contributor Author

@chandrin94 hmm, that's not good - may I ask how you're calling callJsFunction(), and how it seems it isn't working? It's used all over Kweb internally so if it wasn't working at all then almost nothing would work.

@sanity sorry for my late reply. I will give you an example of what i mean.
For version 0.9.0 i initially noticed that elements in my code, like tabs and dropdowns were not getting initialized. After some searching, i tried to execute some js code to examine what goes wrong.

For example, i tried this : browser.callJsFunction("console.log('TEST');"), but nothing was printed in the browser console.
The exact same code worked fine for version 0.8.9 and printed the expected result in the browser console.
For previous versions, browser.execute("console.log('TEST');") also worked fine and printed the word TEST in the browser console.

@Derek52
Copy link
Collaborator

Derek52 commented May 17, 2021

@chandrin94. I discovered a bug in 0.9.0 that prevented browser.callJsFunction() calls from working when there were no arguments. I just released version 0.9.1 that fixes this bug, and it should let you print to the console. I'm not sure if this is going to fix the issues you were having with your tabs and dropdowns.

@chandrin94
Copy link
Contributor Author

chandrin94 commented May 21, 2021

@chandrin94. I discovered a bug in 0.9.0 that prevented browser.callJsFunction() calls from working when there were no arguments. I just released version 0.9.1 that fixes this bug, and it should let you print to the console. I'm not sure if this is going to fix the issues you were having with your tabs and dropdowns.

@Derek52 , @sanity This seems to solve most of the element initialization problems. Another reason was the addClasses(...) function, which does not work since kweb version 0.8.9, so i resorted to using .classes(...) instead., wherever possible. Of course this does not always work, since it can not always replace addClasses(...)

@Derek52 Derek52 closed this as completed Jun 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants