Skip to content

Not rendering helper if collection "hidden" beside Promise #473

Open
@DblK

Description

@DblK

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions