meteor / react-packages

Meteor packages for a great React developer experience
http://guide.meteor.com/react.html
Other
574 stars 159 forks source link

withTracker breaks with renderToNodeStream: SynchronousCursor requires a fiber #251

Closed er-dev closed 3 years ago

er-dev commented 6 years ago

I am trying to use React 16's new renderToNodeStream functionality. I see that support was added Meteor 1.6.1.

The react-meteor-data package's withTracker wrapper does not support renderToNodeStream because SynchronousCursor requires a Fiber in order to run DB queries like Things.find().fetch()

W20180313-14:42:53.055(-7)? (STDERR) Error: Can't wait without a fiber
W20180313-14:42:53.055(-7)? (STDERR)     at Function.wait (/Users/andrew/.meteor/packages/meteor-tool/.1.6.1.lyfx7l.cwu7h++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:159:9)
W20180313-14:42:53.056(-7)? (STDERR)     at Future.wait (/Users/andrew/.meteor/packages/meteor-tool/.1.6.1.lyfx7l.cwu7h++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:448:10)
W20180313-14:42:53.056(-7)? (STDERR)     at SynchronousCursor._nextObject (packages/mongo/mongo_driver.js:1018:47)
W20180313-14:42:53.056(-7)? (STDERR)     at SynchronousCursor.forEach (packages/mongo/mongo_driver.js:1052:22)
W20180313-14:42:53.056(-7)? (STDERR)     at SynchronousCursor.map (packages/mongo/mongo_driver.js:1062:10)
W20180313-14:42:53.056(-7)? (STDERR)     at SynchronousCursor.fetch (packages/mongo/mongo_driver.js:1086:17)
W20180313-14:42:53.056(-7)? (STDERR)     at Cursor.(anonymous function) [as fetch] (packages/mongo/mongo_driver.js:876:44)
W20180313-14:42:53.056(-7)? (STDERR)     at ThingsContainer.jsx.module.exportDefault.withTracker (imports/containers/ThingsContainer.jsx:38:25)
W20180313-14:42:53.057(-7)? (STDERR)     at ReactMeteorDataComponent.getMeteorData (packages/react-meteor-data/ReactMeteorData.jsx:195:12)
W20180313-14:42:53.057(-7)? (STDERR)     at MeteorDataManager.calculateData (packages/react-meteor-data/ReactMeteorData.jsx:37:21)
W20180313-14:42:53.057(-7)? (STDERR)     at ReactMeteorDataComponent.componentWillMount (packages/react-meteor-data/ReactMeteorData.jsx:134:43)
W20180313-14:42:53.057(-7)? (STDERR)     at resolve (/Users/andrew/Development/react/meteor-ssr/node_modules/react-dom/cjs/react-dom-server.node.development.js:2119:12)
W20180313-14:42:53.057(-7)? (STDERR)     at ReactDOMServerRenderer.render (/Users/andrew/Development/react/meteor-ssr/node_modules/react-dom/cjs/react-dom-server.node.development.js:2260:22)
W20180313-14:42:53.057(-7)? (STDERR)     at ReactDOMServerRenderer.read (/Users/andrew/Development/react/meteor-ssr/node_modules/react-dom/cjs/react-dom-server.node.development.js:2234:19)
W20180313-14:42:53.058(-7)? (STDERR)     at ReactMarkupReadableStream._read (/Users/andrew/Development/react/meteor-ssr/node_modules/react-dom/cjs/react-dom-server.node.development.js:2541:38)
W20180313-14:42:53.058(-7)? (STDERR)     at ReactMarkupReadableStream.Readable.read (_stream_readable.js:442:10)
W20180313-14:42:53.058(-7)? (STDERR)     at nReadingNextTick (_stream_readable.js:797:8)
W20180313-14:42:53.058(-7)? (STDERR)     at _combinedTickCallback (internal/process/next_tick.js:135:11)
W20180313-14:42:53.058(-7)? (STDERR)     at process._tickDomainCallback (internal/process/next_tick.js:218:9)
themao commented 5 years ago

Any updates on this? I've been lucky to find this issue, banging my head around this error and trying to wrap it with Meteor.bindEnvironment somehow. So far I switched back to using renderToString.

CaptainN commented 5 years ago

There is new work on a hooks based implementation of withTracker (built on top of useTracker) in #262. It has a very simple server implementation. I wonder if that should be wrapped with Meteor.bindEnvironment by default.

Maybe check that fork out in your local packages directory, add Meteor.bindEnvironment and see if it solves your issue?

function useTrackerServer(reactiveFn) {
  return Meteor.bindEnvironment(reactiveFn)();
}
CaptainN commented 5 years ago

Using Meteor.bindEnvironment didn't work here (though it did stop a weird refresh loop). I actually don't think this is a problem with react-meteor-data because in my package npdev:collections I bypassed useTracker completely, and it still gave me that same error when using renderToNodeStream. There is also this old flow-router issue, which talks about similar issues. I think this may be something in core.

CaptainN commented 5 years ago

Another interesting observation is that even though I get an error:

events.js:183
throw er; // Unhandled 'error' event
^

AssertionError [ERR_ASSERTION]: Cannot await without a Fiber

Everything works just fine.

filipenevola commented 3 years ago

I'm closing this just because it's too old. We can open new issues for items that are still valid.

Most of these items were solved already or replaced by new strategies (like hooks)