Skip to content
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

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

Open
DblK opened this issue Nov 29, 2024 · 1 comment
Open

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

DblK opened this issue Nov 29, 2024 · 1 comment

Comments

@DblK
Copy link

DblK commented Nov 29, 2024

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.

@radekmie
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants