Element focus in onMount works with SSR enabled? Doesn't work with SSR disabled. #10529
Replies: 1 comment
-
Thank you to amsukalski who explained the following:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Issue
Whether ssr is set to true or false here, my onMount fires in the browser. I can see it in the console log, picture attached. That browser log doesn't change when flipping ssr to true or false.
Somehow though, when ssr is false, even tho that log is shown and the element is found easily, the element doesn't focus on app launch. Then I change ssr back to true, and the element focuses on page load every time.
Questions
A: Why would enabling server side logic help focus a ui element on the client side?
B: How can I use the csr onMount to focus an element on page load? (Just putting the onMount code in the script tag made no difference)
Any ideas appreciated, feel like I'm missing something obvious.
Details
onMount is here: https://github.com/bmitchinson/budget-entry/blob/main/src/components/entry/EntryForm.svelte#L32
Also, ignore the App.addListener bit. That's for the app being bundled to an iOS app with Capacitor, which is why I'm interested in CSR only.
That appStateChange code always works great if the focus in the browser works in the first place.
Beta Was this translation helpful? Give feedback.
All reactions