blaze icon indicating copy to clipboard operation
blaze copied to clipboard

Not rendering helper if collection "hidden" beside Promise

Open DblK opened this issue 1 year ago • 1 comments

If you make a simple async helper in conjuction with a meteor collection, during the sync of the collection, the helper is not updated.

I expect the helper to be refreshed once the collection is synced.

  • Blaze: 3.0.1
  • Meteor: 3.0.2

Here is a small code that you explain better the issue. If you move up the line of find.fetch before the async call it's working as expected.

Template.Home.onCreated(() => {
  Tracker.autorun(async () => {
    const user = await Meteor.userAsync();
    Meteor.subscribe('projects', [user?.someProp]); // Help sync Project Meteor Collection
  })
})

Template.Home.helpers({
  // This is not working as expected
  async someHelper(): Promise<string> {

    const someAsyncCall = await myFunction();
    if (someAsyncCall) {
      const projects = Project.find({}).fetch();
      console.log(projects.length) // Always 0
      return 'yeah';
    }

    return ''
  }
  // This is working as expected
  async someHelperWorking(): Promise<string> {

    const someAsyncCall = await myFunction();
    const projects = Project.find({}).fetch();
    if (someAsyncCall) {
      console.log(projects.length) // Always 10 (The amount subscribed)
      return 'yeah';
    }

    return ''
  }
})

Tell me if you need more information.

DblK avatar Nov 29 '24 10:11 DblK

Can you create a repo with a reproduction we could run locally? That'd help immensely!

radekmie avatar Nov 29 '24 10:11 radekmie