Angular SSR Error: FIRESTORE: INTERNAL ASSERTION FAILED: Unexpected state

Viewed 123

So I'm trying to set up SSR for my Angular web app and overall it has been an horrible experience but I've managed to solve the most errors until the following one.

I assume it has to do with my web app's firestore/angularfire dependency only being made for CSR, but I assume there's a way to mock the firestore so I can use my same code for SSR as well, but I'm not understanding on how to it exactly.

The error I get is the following

Error: FIRESTORE (8.3.3) INTERNAL ASSERTION FAILED: Unexpected state
    at fail (D:\Github\CountYourDrinks\dist\Worth-a-shot\server\main.js:103409:11)
    at AsyncQueueImpl.Ea/B.AsyncQueueImpl.verifyNotFailed (D:\Github\CountYourDrinks\dist\Worth-a-shot\server\main.js:125073:13)
    at AsyncQueueImpl.Ea/B.AsyncQueueImpl.enqueue (D:\Github\CountYourDrinks\dist\Worth-a-shot\server\main.js:124972:14)
    at AsyncQueueImpl.Ea/B.AsyncQueueImpl.enqueueAndForget (D:\Github\CountYourDrinks\dist\Worth-a-shot\server\main.js:124959:14)
    at firestoreClientListen (D:\Github\CountYourDrinks\dist\Worth-a-shot\server\main.js:123758:23)
    at onSnapshot (D:\Github\CountYourDrinks\dist\Worth-a-shot\server\main.js:128189:12)
    at CollectionReference$1.Ea/B.Query$1.onSnapshot (D:\Github\CountYourDrinks\dist\Worth-a-shot\server\main.js:128998:16)
    at QueueAction.<anonymous> (D:\Github\CountYourDrinks\dist\Worth-a-shot\server\main.js:137993:35)
    at D:\Github\CountYourDrinks\dist\Worth-a-shot\server\main.js:331222:22
    at ZoneDelegate.crGB.ZoneDelegate.invoke (D:\Github\CountYourDrinks\dist\Worth-a-shot\server\main.js:210824:30)

The error means nothing to me as I cannot say where it comes from in my uncompiled code.

1 Answers

I've had this problem too. I was not able to solve it. If you don't need the firestore data for prerendering for search engines etc., one temporary solution is to skip that code in the server and only show in the browser:

      constructor(@Inject(PLATFORM_ID) private platformId:string) { }

      ngOnInit() {
        if (isPlatformBrowser(this.platformId)) {
           // Add in your firestore code here
        }
      }
Related