meteor / react-packages

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

withTracker behavior changed in Meteor 3 #403

Closed ToyboxZach closed 2 months ago

ToyboxZach commented 2 months ago

I am working on upgrading to Meteor 3 and I have this component

const DataContainer = withTracker(() => {
  const handle = Meteor.subscribe("data");
  let items= [];
  if (handle.ready()) {
    items= Items.find({}, { sort: { CreatedBy: -1 } }).fetch();
  }
  return {
    ready: handle.ready(),
    items: items,
  };
})(ManageItems);

In meteor 2 this works just fine, where it can subscribe and return all the relevant data that I need.

But on Meteor 3 this continually calls the subscribe function and never returns any data. I'm not sure exactly what happens but I imagine it re-rendering constantly and never keeping around the subscription long enough to get data.

I can fix the issue by switching to useTracker, so I know its just a client side issue:


function DataContainer (props: AdminRootProps) {
  const trackerProps = useTracker(() => {
    const handle = Meteor.subscribe("data");
    let items = [];
    if (handle.ready()) {
      items= Items.find({}, { sort: { createdAt: -1 } }).fetch();
    }
    return {
      ready: handle.ready(),
      items: items,
    };
  }, []);
  return <ManageItems{...props} {...trackerProps} />;
}

I am going to just do this upgrade myself, but it seems like this is an unexpected change that might cause other people bigger issues.

denihs commented 2 months ago

Can you share a snippet of the component ManageItems?

Also, can you check if the package react-meteor-data is on version v3.0.0-beta300.1?

If you could also provide a reproduction, it'd be nice. This method should be working with Meteor 3 afaik.

ToyboxZach commented 2 months ago

Oh, sorry, I thought this package would have auto-update like the rest of the meteor packages. I didn't realize it had to be updated separately.

99% of our stuff worked without updating so I assumed this was a special case, updating the package resolves my issue