0

We are showing a bottom sheet when there is a new update available for our Angular PWA. It is inside the SwUpdate.available method. The SwUpdate.available only gets triggered when we run the build command in the server. If we run the build command in local & upload the files to the server, nothing happens. As our server has less RAM, the build command fails most of the time on the server.

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],

})
export class AppComponent implements OnInit {
 
  constructor(
    private swUpdate: SwUpdate,
    private _bottomSheet: MatBottomSheet,
  ) {
    this.checkForUpdates();
  }

  ngOnInit() {}
  
  checkForUpdates() {
    this.swUpdate.available.subscribe(event => {
      this.swUpdate.activateUpdate().then(() => {
        this.openBottomSheet();
      });
    });
  }

  openBottomSheet(): void {
    this._bottomSheet.open(UpdateBottomSheetComponent);
  }
}

  • How are you passing the build event to this method/ – Apoorva Chikara Jan 17 '21 at 12:26
  • @ApoorvaChikara By build command, I mean running ng build --prod. If we run this on server everything works fine but if we run this in local & then upload the generated files to the server available method is not getting triggered. This function is called in the constructor of app.component.ts. – Shiv Singh Jan 17 '21 at 12:48
  • Could you share some more code? – Apoorva Chikara Jan 17 '21 at 13:02
  • @ApoorvaChikara I have updated the code but I don't think it is related to the implementation as it working fine if build on the server. If you need any specific file code let me know I'll update the question. – Shiv Singh Jan 17 '21 at 15:08
  • I think the checkForUpdates() must be called, but swUpdate.available is not getting update. The problem is looking at this piece of code, will be really difficult to understand where is the problem. – Apoorva Chikara Jan 17 '21 at 18:31
  • @ApoorvaChikara I don't think the problem is in the code. Works fine in the local environment. Could be how SWUpdate detects the update. – Shiv Singh Jan 17 '21 at 19:52
  • What is "private swUpdate: SwUpdate" SwUpdate and how are you updating it? – Apoorva Chikara Jan 18 '21 at 07:43

0 Answers0