nitedani / vite-plugin-angular

Vite plugin for Angular, using esbuild and SWC
72 stars 5 forks source link

Routing not working on SSR #12

Closed cskiwi closed 11 months ago

cskiwi commented 11 months ago

Hi,

Me again :) So, in my last issue the SSR got up and running, but it looks like the routing on the SSR isn't working.

To reproduce the er error: starting from the universal example (possible the other examples also):

  1. add a outlet component so the routing can be loaded
    
    import { Component } from '@angular/core';
    import { RouterOutlet } from '@angular/router';

@Component({ standalone: true, imports: [RouterOutlet], template: <router-outlet></router-outlet>, }) export class OutletComponent {}


2. Add some other page component 
```typescript
import { Component } from '@angular/core';

@Component({
  standalone: true,
  template: `<p>Page2 Component</p>`,
})
export class Page2Component {}
  1. Add the routing to the application This is something I wasn't completely sure where this was the correct place, so I added it in the shared.module.ts because I was thinking that the front and backend need the routes. so that would make
    @NgModule({
    imports: [
    RouterModule.forRoot([
      {
        path: '',
        component: AppComponent,
      },
      {
        path: 'page2',
        component: Page2Component,
      },
    ]),
    ],
    providers: [AppService],
    })
    export class SharedModule {
    constructor() {}
    }

Ten when you go to the /page2 url, you see that the AppComponent's code is rendered in the html, once loaded the hydration takes over and does the routing. image

nitedani commented 11 months ago

Sorry for the delay, didn't notice the issue. I forgot to pass url to the server renderer. I'll fix it quickly. Just found out gmail put all github notifications to my spam folder 🤦

nitedani commented 11 months ago

Fixed in 17.0.8

cskiwi commented 11 months ago

@nitedani Strange that your mails went to the spam folder, hopefully it wasn't because I post to much? :P

Thanks for the fix, but now I get some differet error regarding the tsconfig. was there another change? I tried looking at the commits, but couldn't spot what would cause this issue.

@vavite/reloader: Loading server entry
  ➜  Local:   http://localhost:5200/
  ➜  Network: use --host to expose
Error:   Failed to scan for dependencies from entries:
  <location>/herring-gull-angular/apps/gull/index.html

  X [ERROR] TS500: Error: ENOENT: no such file or directory, lstat '<location>/herring-gull-angular/tsconfig.json'
    at Object.lstatSync (node:fs:1660:3)
    at NodeJSFileSystem.lstat (file:///<location>/herring-gull-angular/node_modules/@angular/compiler-cli/bundles/chunk-PCMLSPQF.js:341:16)
    at calcProjectFileAndBasePath (file:///<location>/herring-gull-angular/node_modules/@angular/compiler-cli/bundles/chunk-EKZWOVDR.js:8573:29)
    at readConfiguration (file:///<location>/herring-gull-angular/node_modules/@angular/compiler-cli/bundles/chunk-EKZWOVDR.js:8599:39)
    at <location>\herring-gull-angular\node_modules\@angular-devkit\build-angular\src\tools\esbuild\angular\compilation\angular-compilation.js:53:69
    at profileSync (<location>\herring-gull-angular\node_modules\@angular-devkit\build-angular\src\tools\esbuild\profiling.js:68:16)
    at AotCompilation.loadConfiguration (<location>\herring-gull-angular\node_modules\@angular-devkit\build-angular\src\tools\esbuild\angular\compilation\angular-compilation.js:53:44)
    at async AotCompilation.initialize (<location>\herring-gull-angular\node_modules\@angular-devkit\build-angular\src\tools\esbuild\angular\compilation\aot-compilation.js:50:100)
    at async initialize (<location>\herring-gull-angular\node_modules\@angular-devkit\build-angular\src\tools\esbuild\angular\compilation\parallel-worker.js:33:50)

    at async <location>\herring-gull-angular\node_modules\piscina\dist\src\worker.js:141:26 [plugin angular-compiler]

    at failureErrorWithLog (<location>\herring-gull-angular\node_modules\esbuild\lib\main.js:1650:15)
    at <location>\herring-gull-angular\node_modules\esbuild\lib\main.js:1059:25
    at <location>\herring-gull-angular\node_modules\esbuild\lib\main.js:1526:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
nitedani commented 11 months ago

I think I know what the issue is. Yes, I moved swc to be optional in dev, in favor of dev and prod consistency and dev type checking. For the previous behavior pass {swc:true} to the plugin in vite config.

nitedani commented 11 months ago

I'll fix it later tonight.

nitedani commented 11 months ago

Should be fixed in 17.0.10

cskiwi commented 11 months ago

@nitedani validating and working now! thanks

I'll continue here with the next issue if that's not a problem :) Beacuause with one of the updates the scss isn't being compiled anymore, on the left you see the the server running version 17.0.6 and on the right you see the same code but the @niteadani/ packages on version 17.0.10

This mostly isn't a big issue, but I don't think this was expected behaviour

image

nitedani commented 11 months ago

I see the problem, I'll fix it this weekend.

nitedani commented 11 months ago

Should be fixed in 17.0.11 What's changed:

cskiwi commented 11 months ago

Thanks @nitedani all seem to work now! some styling doesn't seem to be applied when doing the SSR, but for that I will do some research first if this is a bug or just how SSR works :)