Skip to content

bug: angular, cannot read property of 'whenDefined' with ssr #24714

@vitordhers

Description

@vitordhers

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

Folks, I'm using the brand new Ionic 6, trying to integrate it with Angular Universal through NestJs. It was working pretty well, until I noted that I was getting this error when running using server side rendering:
Menu: must have a "content" element to listen for drag events on.
After some time, I noticed that the <ion-menu-button> wasn't working. I tried using it programmatically using the MenuController, but it also didn't work.
I run the code without SSR and the button was working properly. So I went out to find out what was the issue and I found this issue (#21918 (comment)) where the solution apparently was to add @ionic/angular-server to my Angular AppModule. I did so, but now every time I try to access Angular's pages, I'm getting this error (in server console):
ReferenceError: Cannot access 'ActionSheet' before initialization
and this one (browser console):
Uncaught SyntaxError: Strict mode code may not include a with statement
I tried to search for those issues but sadly I couldn't find much related.
If I remove IonicServerModule from AppModule the code runs, but the button naturally still doesn't work.

I'm not sure why this is happening. Is there any error with the Ionic version I'm using? Any substantial package that I'm missing?

From the SSR standpoint I understand that menu's contentId looks for its sibling with same id as it, and since that document is not available in that context, in fact, the menu won't have any content at all. But in browser, that doesn't make much sense. I also tried to conditionally render <ion-menu> tags for platform browsers. The Menu: must have a "content" element to listen for drag events on. error disappear, but still <ion-menu-button> isn't working.
Any insights on this matter?
I really appreciate it, thanks in advance.

Expected Behavior

The menu button should work after the implementation of IonicServerModule.

Steps to Reproduce

For reproducing issue with IonicServerModule

  1. Download repo from code reproduction URL and Install dependencies;
  2. Try running npm run dev:ssr or npm run serve:ssr;
  3. Check logs on console when trying to access localhost:4200.

For reproducing issue with <ion-menu-button> not working / Menu: must have a "content" element to listen for drag events on.:

  1. Download repo from code reproduction URL;
  2. Remove IonicServerModule from AppModule (src/app/app.module.ts);
  3. Run npm run dev:ssr or npm run serve:ssr;
  4. Access localhost:4200/home;
  5. Resize screen to <768px;
  6. Click on hamburger icon at top right corner of the screen.

Code Reproduction URL

https://github.com/vitordhers/confraria

Ionic Info

Ionic:

Ionic CLI : 6.18.1 (/usr/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 6.0.5
@angular-devkit/build-angular : 13.1.4
@angular-devkit/schematics : 13.1.4
@angular/cli : 13.1.4
@ionic/angular-toolkit : 4.0.0

Utility:

cordova-res : not installed globally
native-run (update available: 1.5.0) : 1.4.1

System:

NodeJS : v16.13.2 (/home/dina/.nvm/versions/node/v16.13.2/bin/node)
npm : 8.1.2
OS : Linux 5.13

Additional Information

Content related with cannot access "action-sheet" before initialization:
#24448
Content related with Uncaught SyntaxError: Strict mode code may not include a with statement:
https://stackoverflow.com/questions/60114758/uncaught-syntaxerror-strict-mode-code-may-not-include-a-with-statement

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions