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

isReady() returns false right after "await ready()" promise #22

Open
hems opened this issue Apr 10, 2020 · 16 comments
Open

isReady() returns false right after "await ready()" promise #22

hems opened this issue Apr 10, 2020 · 16 comments

Comments

@hems
Copy link
Contributor

hems commented Apr 10, 2020

On my current test i have a simple publication which publishes 3 notifications

// server pub
Meteor.publish('unread.notifications', () => {
   return Notifications.find({})
}

And that subscription on the client

// client
  const notificationsUnreadSub = server.subscribe("notifications.unread");
  await notificationsUnreadSub.ready();

  const notificationsCursor = server.collection('notifications')
    .reactive()
    
  console.log("is ready ->", notificationsUnreadSub.isReady())
  console.log("data ->", notificationsCursor.data())

And this is my console output:

is ready -> false
unreadNotifications.js:14 data -> (3) [{…}, {…}, {…}]

The unexpected thing is that my console log says "is ready: false" right after the subscription but my ".data()" call returns the only 3 subscriptions that exist.

Is there a reason for the "isReady()" to not be true right after waiting for the promise?

@hems
Copy link
Contributor Author

hems commented Apr 10, 2020

Also, I have an "onChange" listener which is triggered 6 times even tough there are only 3 notifications and I just did "await notificationsCursorready().

  const notificationsUnreadSub = server.subscribe("notifications.unread");
  await notificationsUnreadSub.ready();

  const notificationsCursor = server.collection('notifications').reactive()

  // this is triggered 6 times even tough i just "awaited" for ready() 
  // and there are only 3 documents.
  notificationsCursor.onChange(function (data) {
    console.log("n changed ->", notificationsUnreadSub.isReady())
  })

@Gregivy
Copy link
Owner

Gregivy commented Apr 10, 2020

Can not reproduce your issues, please provide full example code that behaves as you wrote.

@hems
Copy link
Contributor Author

hems commented Apr 10, 2020

Can not reproduce your issues, please provide full example code that behaves as you wrote.

cool, I'll make a bare meteor repo and send it to you, indeed that will make things easier sorry about not have sent you yet, i released that if i only send the Next.js app it might not be enough for you to test and it's not easy to send just the meteor methods, so I'll create a new empty repo and let you know.

thank you for the project and your quick responses!

@Gregivy
Copy link
Owner

Gregivy commented Apr 11, 2020

You are welcome! Hope we will find what is wrong quick enough.

@aogaili
Copy link

aogaili commented Apr 13, 2020

@Gregivy perhaps you suggestion here will decrease the encounter of such issues.

What do you think?

@Gregivy
Copy link
Owner

Gregivy commented Jun 4, 2020

@aliogaili have implemented this but not released yet.

@hems By the way if you wait for ready it means you wait for 'ready' message from the server, it doesn't guarantee that the server will send any data before (actually it does if you use vanilla Meteor or you use custom publications with added() removed() and changed() and have full control of it). I can't tell more without a code.

@aogaili
Copy link

aogaili commented Jun 4, 2020

Hey @Gregivy I've not changed anything in SimpleDDP, I've been using for a few months now and it is working great. However, we're using it mostly to execute RPC DDP methods.

The only thing that I had to do is handle socket connection disconnect more aggressively by forcing setInterval and connect and I used a react component for that.

@Gregivy
Copy link
Owner

Gregivy commented Jun 4, 2020

@aliogaili I mean that I have added the maxTimeout support for the connect() method, I will soon publish all new fixes on npm :) Its nice to hear that you use simpleddp btw :)

@aogaili
Copy link

aogaili commented Jun 5, 2020

@Gregivy I'm a big fan of SimpleDDP and I've been recommending it a lot, so thanks a lot for maintaining it.

I'm thinking of creating a boilerplate on top of SimpleDDP and calling it SimlpePWA. Basically, it's a React Static PWA app that can be hosted on CDN and communicate with Meteor backend using SimpleDDP.

@Gregivy
Copy link
Owner

Gregivy commented Jun 6, 2020

@aliogaili Thanks for the good words :) About PWA, its a good idea, I have also done it several times by hands, so it will definitely be a useful tool.

@hems
Copy link
Contributor Author

hems commented Jun 10, 2020

@Gregivy I'm a big fan of SimpleDDP and I've been recommending it a lot, so thanks a lot for maintaining it.

I'm thinking of creating a boilerplate on top of SimpleDDP and calling it SimlpePWA. Basically, it's a React Static PWA app that can be hosted on CDN and communicate with Meteor backend using SimpleDDP.

good stuff!

I have also created a few React Hooks to handle "Subscriptions", "Methods" and "Login" which i could also share if you guys create such React related templates / project.

@hems
Copy link
Contributor Author

hems commented Jun 10, 2020

@aliogaili I mean that I have added the maxTimeout support for the connect() method, I will soon publish all new fixes on npm :) Its nice to hear that you use simpleddp btw :)

Yes it's been a life saver to be honest, thank you very much for the library!

@hems
Copy link
Contributor Author

hems commented Jun 10, 2020

I'm thinking of creating a boilerplate on top of SimpleDDP and calling it SimlpePWA. Basically, it's a React Static PWA app that can be hosted on CDN and communicate with Meteor backend using SimpleDDP.

I'm using it with next.js and it's an amazing combo!

Then if users need the server-side part of next.js then they could host on a regular node.js host, but if it's just client, next.js can export just the "static version" which would be suitable for CDN!

@aogaili
Copy link

aogaili commented Jun 10, 2020

Yeah, I'm using with a PWA created using Static CRA + React MUI hosted on CDN (Surge) connected to a Meteor system/backend.

It is a killer combo frankly! That is why I think it is worth creating a boilerplate with this setup.

@hems
Copy link
Contributor Author

hems commented Jun 10, 2020

Yeah, I'm using with a PWA created using Static CRA + React MUI hosted on CDN (Surge) connected to a Meteor system/backend.

It is a killer combo frankly! That is why I think it is worth creating a boilerplate with this setup.

The only problem I see is the lack of SEO and that's why we're moving from client-side only app to next.js on our project, it worked "ok-ish" with work-arounds on Meteor, but turns out we now really real SSR / HTTP Status Code and that isn't possible if the application is client-side only, hence why i think next.js is the way to go, it can do Static client-sid only but also can make SEO / Server-side if you need.

@aogaili
Copy link

aogaili commented Jun 10, 2020

Yeah, I get it. In our case SSR in the client app is not important, we have a landing page where the SSR is needed and we wanted the static site to manage the scale and avoid the server rendering (a.k.a JAMStack).

However, in the dashboard/admin, we've used Meteor SSR to handle some custom client bootstrapping code.

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

3 participants