-
-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onMounted is being called prior to FormKit being ready on page transitions #352
Comments
It's definitely a case of FormKit not being fully updated before onMounted. Even if I take everything out, and give everything unique names and IDs, the onMounted seems to be returning elements from the previously loaded page. So, maybe a different question, is there a better event to call focus() in to ensure that the FormKit form is ready? |
onMounted should work just fine, we use that pretty frequently. I checked out the reproduction but I'm unable to get it to boot up — could you make a minimum repro on stackblitz or a vanilla nuxt3? |
Strange. Let me see if I can narrow it down. |
Here you go. View console. You'll see the element being found in onMounted is not the one rendered. https://stackblitz.com/edit/github-vqvsuh-bnkwij?file=pages/second.vue This one is the same thing but with completely unique ids and names to confirm its not that. |
Thanks for those repros. So it looks like Nuxt wraps its pages in a If you want to disable this default If you find an alternate workaround I'd be interested. |
Thank you! Found the upstream bugs: Vue3 Bug: For anybody else struggling with this, you can either disable transitions or wrap all the code that needs to read the DOM in onMounted in a setTimeout (until the upstream bug is fixed):
|
Reproduction
https://github.com/JohnCampionJr/nuxt3-net6-starter/tree/wip
Describe the bug
Setting up a test / starter nuxt3 app for my use.
Trying out the auto prop plugin and I'm finding a problem in the onMounted() lifecycle hook.
It appears that the FormKit has not always updated the DOM by the time this event fires, so on back to back pages with similarly named inputs, the onmounted is not catching the right element.
You can see it in my repo (no need for dot net backend) just start it up and click between the two validation pages and watch the console. It's not grabbing the right element.
I've tried nextTick and setTimeout, with no luck. I've also disabled the plugin for testing.
Environment
• OS: Windows
• Browser Edge, Chrome
• Version latest
The text was updated successfully, but these errors were encountered: