vue-meteor icon indicating copy to clipboard operation
vue-meteor copied to clipboard

Trying to SSR Meteor collection results in Fibers error

Open mizzao opened this issue 7 years ago • 3 comments

Using Vue 2.5.9 and the same package versions as the latest commit of vue-meteor-demo, I am trying to do a v-for over a subscription:

<template>
  <div>
    <h1>Dataset Browser</h1>
    <div v-for="data in datasets">
      {{ data.timestamp }}
    </div>
  </div>
</template>

<script>
  import { Datasets } from '/imports/data/collections';

  export default {
    data: function () {
      return {
        datasets: []
      }
    },

    meteor: {
      $subscribe: {
        'data_all'() {
          return []; // No arguments
        }
      },
      datasets() {
        return Datasets.find();
      }
    }
  }
</script>

As far as I can tell this is doing the same thing as the Notes example. However, I'm getting the following SSR error (which goes away if I take out the v-for):

W20171208-16:54:07.131(-5)? (STDERR) Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
W20171208-16:54:07.135(-5)? (STDERR)     at Object.Meteor._nodeCodeMustBeInFiber (packages\meteor.js:1138:11)
W20171208-16:54:07.136(-5)? (STDERR)     at Meteor.EnvironmentVariable.EVp.get (packages\meteor.js:1151:10)
W20171208-16:54:07.138(-5)? (STDERR)     at renderer.renderToString (packages/akryum:vue-ssr/server/index.js:129:56)
W20171208-16:54:07.139(-5)? (STDERR)     at RenderContext.done (C:\Users\maoan\AppData\Local\.meteor\packages\akryum_vue-ssr\0.2.1\npm\node_modules\vue-server-renderer\build.js:6792:11)
W20171208-16:54:07.140(-5)? (STDERR)     at RenderContext.next (C:\Users\maoan\AppData\Local\.meteor\packages\akryum_vue-ssr\0.2.1\npm\node_modules\vue-server-renderer\build.js:161:17)
W20171208-16:54:07.142(-5)? (STDERR)     at RenderContext.cachedWrite [as write] (C:\Users\maoan\AppData\Local\.meteor\packages\akryum_vue-ssr\0.2.1\npm\node_modules\vue-server-renderer\build.js:30:9)
W20171208-16:54:07.144(-5)? (STDERR)     at RenderContext.next (C:\Users\maoan\AppData\Local\.meteor\packages\akryum_vue-ssr\0.2.1\npm\node_modules\vue-server-renderer\build.js:172:14)
W20171208-16:54:07.145(-5)? (STDERR)     at RenderContext.cachedWrite [as write] (C:\Users\maoan\AppData\Local\.meteor\packages\akryum_vue-ssr\0.2.1\npm\node_modules\vue-server-renderer\build.js:30:9)
W20171208-16:54:07.146(-5)? (STDERR)     at RenderContext.next (C:\Users\maoan\AppData\Local\.meteor\packages\akryum_vue-ssr\0.2.1\npm\node_modules\vue-server-renderer\build.js:172:14)
W20171208-16:54:07.148(-5)? (STDERR)     at cachedWrite (C:\Users\maoan\AppData\Local\.meteor\packages\akryum_vue-ssr\0.2.1\npm\node_modules\vue-server-renderer\build.js:30:9)

Removing the code that sets VueSSR.createApp makes everything work fine on the client.

mizzao avatar Dec 08 '17 22:12 mizzao

Tested the Promise form of VueSSR.createApp (described here) and that results in the same error as well.

mizzao avatar Dec 08 '17 22:12 mizzao

Encountering the same issue myself.

On my end, It only appears to happen when a Vue component fetches more than 25 entries from a collection.

This works

export default {

    ...

    meteor: {
        $subscribe: {
            'shop.products'() {
                return [this.$settings._id];
            },
        },

        products() {
            // This works perfectly.
            return Products.find({ shopId: this.$settings._id }, { limit: 25 });
        },
    },

    ...

}

This throws a Fiber error

export default {

    ...

    meteor: {
        $subscribe: {
            'shop.products'() {
                return [this.$settings._id];
            },
        },

        products() {
            // This throws a Fiber error.
            return Products.find({ shopId: this.$settings._id }, { limit: 26 });
        },
    },

    ...

}

JorgenVatle avatar May 30 '18 18:05 JorgenVatle

After adding and removing a limit to the server-side publication, the issue appears to have just gone away. Both for development and simulated production environments.

JorgenVatle avatar May 30 '18 19:05 JorgenVatle