Meteor-Community-Packages / meteor-autoform

AutoForm is a Meteor package that adds UI components and helpers to easily create basic forms with automatic insert and update events, and automatic reactive validation.
MIT License
1.44k stars 328 forks source link

Autoform hooks onSuccess not working #1710

Closed timsun28 closed 1 year ago

timsun28 commented 2 years ago

After recently up Meteor from 2.1.1 to 2.4 I have noticed an issue with my Autoform hooks. Noticeably only on the insert hooks, where only the before - insert hook runs well. I use the onSuccess hook for certain functionalities, but it is not getting triggered.

The onSuccess hooks for update forms are working properly.

The insert process does however work properly. So the element that needs to get inserted does get inserted into the database without an error. A separate issue that comes from this is that the form is not getting cleared after an insert, but it does show up in the data table.

I would like to know if anyone else is having similar issues and if they managed to solve the problem. I have tried working with simpleschema and autoform debugging modes on, but i'm not receiving any console logs from both packages.

Versions (please complete the following information):

I'm using blaze for rendering, and the issue has only started since the last update i've done.

One thing I did try out was to use the matb33:collection-hooks package to create a hook for inserts and this was successful. But before I am going to replace all my onSuccess functions to the collection hook I would like to know if there is a better way to fix this issue.

In that update my following packages were updated: meteor-base@1.5.1 mongo@1.13.0 standard-minifier-css@1.7.4 standard-minifier-js@2.7.0 ecmascript@0.15.3 ecmascript-runtime@0.8.0 ecmascript-runtime-client@0.12.0 ecmascript-runtime-server@0.11.0 dynamic-import@0.7.1 accounts-password@2.1.0 accounts-base@2.1.0 alanning:roles@3.4.0 babel-compiler@7.7.0 blaze@2.5.0 blaze-html-templates@1.2.1 blaze-tools@1.1.2 caching-html-compiler@1.2.0 callback-hook@1.4.0 ddp-client@2.5.0 ddp-rate-limiter@1.1.0 ddp-server@2.5.0 email@2.2.0 fourseven:scss@4.15.0 html-tools@1.1.2 htmljs@1.1.1 http@1.4.4 id-map@1.1.1 launch-screen@1.3.0 logging@1.3.1 matb33:collection-hooks@1.1.0 meteor@1.10.0 meteor-base@1.5.1 minifier-css@1.6.0 minifier-js@2.7.1 minimongo@1.7.0 modern-browsers@0.1.6 modules@0.17.0 mongo-id@1.0.8 montiapm:agent@2.44.2 montiapm:meteorx@2.2.0 npm-mongo@3.9.1 observe-sequence@1.0.19 pfafman:filesaver@1.3.2_1 promise@0.12.0 react-fast-refresh@0.1.1 routepolicy@1.1.1 service-configuration@1.2.0 socket-stream-client@0.4.0 spacebars@1.2.0 spacebars-compiler@1.2.1 standard-minifier-css@1.7.4 standard-minifier-js@2.7.1 templating@1.4.1 templating-compiler@1.4.1 templating-runtime@1.5.0 templating-tools@1.2.0 url@1.3.2 webapp@1.12.0
jankapunkt commented 2 years ago

hi @timsun28 would you mind proving me a short reproducible example?

timsun28 commented 2 years ago

Hi @jankapunkt , I have created a quick demo in this empty project that gives me the same issue as in my personal project: https://github.com/timsun28/autoform-test

You can pull it directly from the repo and run as usual. I have copied my package lists so you can more easily debug what issue could be causing this.

Hope this helps, thank you!

jankapunkt commented 2 years ago

I reproduced it but I can't find why it's like that. I will have to do some research and also see if there are uncovered tests.

timsun28 commented 2 years ago

Thank you for letting me know, I will also continue to look into it so will update if I find a solution or more info.

cheesington commented 2 years ago

I looked at the package list, and noticed matb33:collection-hooks in there. I recently tried to add that package to a project that was using Autoform's hooks, and had the same problem -- the onSuccess hook stopped firing. That might be a place to start looking.

That project is still using Meteor 2.1.1, though.

timsun28 commented 2 years ago

@cheesington Thanks for your message. I also tried the hook from that package and it worked properly for inserts. So i'm now using that function to do my processing, but I would prefer to use the autoform functions again. When I get too it I will try and remove that package as I wasn't actively using it for anything else prior to the issues and report back.

cheesington commented 2 years ago

Yeah, I had to remove the collection-hooks package from the project to get the Autoform onSuccess hook to work again. I was using .after.insert on an unrelated collection, so it took a little while to notice the correlation.

I suspect that Autoform and collection-hooks do some monkey patching of the same code.

Please do report back.

jankapunkt commented 2 years ago

I am still investigating, since tests on the one hand do not show siginificant issues but there is also some coverage missing so I currently try to go the test-driven way to find out what's actually going on there

timsun28 commented 2 years ago

I can also confirm that by removing the collection-hooks package fixed the issues that I was having. Luckily this wasn't a package that I was actively using for anything, so my issue was quickly resolved.

Hope you can find a fix eventually for this issue or discuss it with the devs from collection-hooks.

angel-li commented 2 years ago

Have there been any progress on resolving this issue? Unfortunately I can not easily remove collectioon-hooks from my app.

timsun28 commented 2 years ago

I haven't had the problem anymore since removing the package, but if this is not possible for you, you can try to create a fix for either autoform or collection-hooks by renaming a certain function that causes the issue.

Just some random idea that could be worth looking into, is the order of your package list. You could try to load one before or after the other so that Autoform has priority over the function name. I believe that collection-hooks was overwritting one of the autoform functions on a collection, because for me the colllection-hooks was still working when the autoform wasn't.

Hope you are able to find a solution to your problem!

jankapunkt commented 2 years ago

There is a PR on this now: https://github.com/Meteor-Community-Packages/meteor-collection-hooks/pull/283

StorytellerCZ commented 1 year ago

Released in v1.1.3