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

support async logic inside ssr renderer #367

Open
lifeart opened this issue Oct 17, 2021 · 1 comment
Open

support async logic inside ssr renderer #367

lifeart opened this issue Oct 17, 2021 · 1 comment

Comments

@lifeart
Copy link
Contributor

lifeart commented Oct 17, 2021

it will be great to have possibility to provide kinda "waiters" to ssr render functions, to allow render some lazy-loaded components or components with async data.

awaiters could be registered on the fly, during initial rendering

renderToString(App, { awaiter } );
class App extends Component {
   constructor(owner, args) {
      super(owner, args);
      // sync awaiter registration;
      this.onComponentLoaded = this.args.awaiter.register("componentLoaded");
      import('components/my-component').then((result) => {
         this.componentToRender = result.default;
         setTimeout(() => {
              // async awaiter  resolution
              this.onComponentLoaded.resolve();
          });
      })
   }
}
class App extends Component {
   @tracked data;
   constructor(owner, args) {
      super(owner, args);
      // sync awaiter registration;
      this.onDataLoaded = this.args.awaiter.register("dataLoaded");
      fetch('api/users').then(result => result.toJSON()).then((data) => {
                  this.data = data;
                  setTimeout(() => {
                        this.onDataLoaded.resolve();
                   });
       });
   }
}

renderToString function should wait for all awaiters to be resolved before returning output

// awaiter may be an global hook, to simplify it's usage inside components

@lifeart
Copy link
Contributor Author

lifeart commented Oct 19, 2021

looks like best way to do it, is use "Vue" way, having independent router instance, and resolve all nessesary deps before rendering.

see "addResolver" section josemarluedke/glimmer-apollo#48 (comment)

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

1 participant