Skip to content

With Options API, $subReady is not working when subscribing outside of meteor object. #79

Open
@mlanning

Description

@mlanning

Currently using

"vue": "^3.2.37",
"vue-meteor-tracker": "^3.0.0-beta.7",

Here is a working example that I adapted from the Akyryum/meteor-vite project.

https://github.com/mlanning/example-vue-meteor-tracker

<template>
  <div class="flex flex-col gap-4">
    <h1 class="text-2xl">Learn Meteor!</h1>
    <ul>
      <li
        v-for="link of links"
        :key="link._id"
      >
        <a :href="link.url" target="_blank" class="underline">
          {{ link.title }}
        </a>
      </li>
    </ul>
    <pre class="bg-gray-100 rounded p-4">{{ { $subReady } }}</pre>
    <p v-if="$subReady.links">$subReady.links is true</p>
    <p v-if="!$subReady.links">$subReady.links is false</p>
  </div>
</template>

When subscribing to links in a meteor object, $subReady.links returns true in the template.

<script lang="ts">
import { defineComponent } from 'vue'
import { LinksCollection } from '/imports/api/links'

export default defineComponent({
  meteor: {
    $subscribe: {
      links: [],
    },
    links () {
      return LinksCollection.find({}).fetch()
    },
  },
  // mounted() {
  //   this.$subscribe('links')
  // }
})
</script>

Screenshot 2022-12-06 at 15 46 15

However, when I try to subscribe from the mounted() lifecycle hook, $subReady.links returns false in the template.

<script lang="ts">
import { defineComponent } from 'vue'
import { LinksCollection } from '/imports/api/links'

export default defineComponent({
  meteor: {
    // $subscribe: {
    //   links: [],
    // },
    links () {
      return LinksCollection.find({}).fetch()
    },
  },
  mounted() {
    this.$subscribe('links')
  }
})
</script>

Screenshot 2022-12-06 at 15 40 36

Also, Meteor dev tools shows the subscription as ready.
Screenshot 2022-12-06 at 16 05 15

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