Giter Club home page Giter Club logo

Comments (6)

a-syde avatar a-syde commented on June 2, 2024 1

@mohamedaarab1994 Have you got any updates on this?
Angular doesn't bootstrap client side at all, therefore there is no JS code at all. Only links work.
Preboot works as it should when you run:
"dev:ssr": "ng run frontend:serve-ssr"
It is really frustrating 😞
image

from preboot.

akshata456 avatar akshata456 commented on June 2, 2024

@CaerusKaru any update on this? I'm facing the same issue in angular 9

from preboot.

shyamal890 avatar shyamal890 commented on June 2, 2024

I am facing the same issue, can you please update us on this please.

from preboot.

ocombe avatar ocombe commented on June 2, 2024

I had the same issue until I realized that appId and appRoot need to be the same:

In my AppModule:

BrowserModule.withServerTransition({ appId: 'app-root' }),
PrebootModule.withConfig({ appRoot: 'app-root' })

After that, everything worked like a charm.

from preboot.

akshata456 avatar akshata456 commented on June 2, 2024

I had the same issue until I realized that appId and appRoot need to be the same:

In my AppModule:

BrowserModule.withServerTransition({ appId: 'app-root' }),
PrebootModule.withConfig({ appRoot: 'app-root' })

After that, everything worked like a charm.

It works for me .Thanks.

from preboot.

ocombe avatar ocombe commented on June 2, 2024

Ok another reason why this might fail: preboot uses the observable appRef.isStable, which might never get stable because according to the documentation:

the application will never be stable if you start any kind of recurrent asynchronous task when the application starts (for example for a polling process, started with a setInterval, a setTimeout or using RxJS operators like interval);

These asynchronous tasks can be in your code (setTimeout, setInterval, or interval operator), or in any of your external libraries... making it very hard to debug.

A solution is to manually do the cleanup:

  • Inject EventReplayer in your code
  • call this.eventReplayer.replayAll();

This will make the replay of events, and then the cleanup of the server side application. You will be responsible for making sure that your app is loaded, otherwise you'll see a nice FOC when it switches from one app to the other...
If you're not replaying events, you can directly call this.eventReplayer.cleanup();

To help you detect pending async events such as setInterval, you can use the following code in your main.ts file:

document.addEventListener('DOMContentLoaded', () => {
  platformBrowserDynamic()
    .bootstrapModule(AppModule)
    .then(moduleInstance => {
      // Ensure Angular destroys itself on hot reloads.
      if (window['ngRef']) {
        window['ngRef'].destroy();
      }
      window['ngRef'] = moduleInstance;
      const ngZone = moduleInstance.injector.get(NgZone);
      setInterval(() => {
        const taskTrackingZone = (<any>ngZone)._inner.getZoneWith('TaskTrackingZone');
        if (!taskTrackingZone) {
          throw new Error(
            `'TaskTrackingZone' zone not found! Have you loaded 'node_modules/zone.js/dist/task-tracking.js'?`
          );
        }
        let tasks: any[] = taskTrackingZone._properties.TaskTrackingZone.getTasksFor('macroTask');
        tasks = clone(tasks);
        if (size(tasks) > 0) {
          console.log('ZONE pending tasks', tasks);
        }
      }, 1000);
      // Otherwise, log the boot error
    })
    .catch((error: string) => {
      /* tslint:disable-next-line */
      console.error(error);
    });
});

And add import 'zone.js/dist/task-tracking'; in your polyfill.ts file

from preboot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.