Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slow server response time in dynamic routes when using Angular SSR #55021

Closed
majidkhaleghian opened this issue Mar 24, 2024 · 8 comments
Closed
Labels
area: server Issues related to server-side rendering needs reproduction This issue needs a reproduction in order for the team to investigate further
Milestone

Comments

@majidkhaleghian
Copy link

Which @angular/* package(s) are the source of the bug?

platform-server

Is this a regression?

Yes

Description

When I used Angular SSR, some pages were loading with a very high delay. At first, I couldn't figure out where the problem was and I did a lot of checking.

Finally, I realized that the delay occurs when a route has a param. For example, the initial fetch of other pages took 10ms, but pages with a route with a param took close to 1s.

Suppose we have a blog and the route is as follows:

blog/:slug

In this case, for example, the page blog/my-article will load with a delay of close to 1s..

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.2.1
Node: 20.10.0
Package Manager: npm 10.2.3
OS: win32 x64

Anything else?

No response

@sonukapoor sonukapoor added the area: server Issues related to server-side rendering label Mar 24, 2024
@ngbot ngbot bot added this to the needsTriage milestone Mar 24, 2024
@alxhub alxhub added the needs reproduction This issue needs a reproduction in order for the team to investigate further label Mar 25, 2024
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Mar 25, 2024
@alxhub
Copy link
Member

alxhub commented Mar 25, 2024

Without a reproduction, it will be impossible to diagnose and verify this report. For example, we don't know what the difference in the two routes is - perhaps the route with a slug is waiting on a database call to load.

@majidkhaleghian
Copy link
Author

Without a reproduction, it will be impossible to diagnose and verify this report. For example, we don't know what the difference in the two routes is - perhaps the route with a slug is waiting on a database call to load.

You can find an example in blog section of this website:

parsouatravel.com/blog

Here are the codes of the blog.routes.ts file:

export default [
    { path: '', component: BlogMainComponent },
    { path: 'aurora-borealis', component: BlogArticleComponent, data: { slug: 'aurora-borealis' } },
    { path: 'scandinavia-nordics-of-europe', component: BlogArticleComponent, data: { slug: 'scandinavia-nordics-of-europe' } },
    { path: 'travel-without-a-visa', component: BlogArticleComponent, data: { slug: 'travel-without-a-visa' } },
    { path: 'finnish-foods', component: BlogArticleComponent, data: { slug: 'finnish-foods' } },
    { path: 'sultan-begum-mansion', component: BlogArticleComponent, data: { slug: 'sultan-begum-mansion' } },
    { path: 'french-croissants-and-austrian-roots', component: BlogArticleComponent, data: { slug: 'french-croissants-and-austrian-roots' } },
    { path: 'disneyland', component: BlogArticleComponent, data: { slug: 'disneyland' } },
    { path: 'blast-off-barcelona-beaches', component: BlogArticleComponent, data: { slug: 'blast-off-barcelona-beaches' } },
    { path: 'charles-bridge', component: BlogArticleComponent, data: { slug: 'charles-bridge' } },
    **{ path: ':slug', component: BlogArticleComponent },**
    { path: 'category/:category', component: BlogCategoryComponent },
] satisfies Route[];

In order to prevent high-traffic pages from loading slowly, I had to manually enter some slugs, but I left the rest dynamic.

I passed the parameter for the API call in manual routes through data. This is a part of the code from the blog-article.component.ts file:

    const data = this.activatedRoute.snapshot.data['slug'];
    if (data) {
      this.slug = data;
      this.init();
    } else {
      this.activatedRoute.params.subscribe(params => {
        if (params['slug']) {
          this.slug = params['slug'];
          this.init();
        }
      });
    }

The initial document load time for this link parsouatravel.com/blog/aurora-borealis (the route I entered manually) is only 50 ms.

However, the initial document load time for this link that I did not enter manually parsouatravel.com/blog/the-lion-s-rock is 1.03 s

The speed of retrieving data from the database and API call does not make much difference.

@alan-agius4
Copy link
Contributor

@majidkhaleghian, kindly provide a runnable minimal reproduction.

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

@atscott
Copy link
Contributor

atscott commented Mar 28, 2024

Closing due to lack of a runnable reproduction.

If the problem still exists in your application, please open a new issue and follow the instructions in the issue template.

@atscott atscott closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2024
@michaelhunziker
Copy link

michaelhunziker commented Apr 24, 2024

@majidkhaleghian Did you find a solution for your issue? We're experiencing the exact same delay using the "**" wildcard route for the same usecase as yours (loading dynamic slugs for a cms).

@majidkhaleghian
Copy link
Author

@majidkhaleghian Did you find a solution for your issue? We're experiencing the exact same delay using the "**" wildcard route for the same usecase as yours (loading dynamic slugs for a cms).

Unfortunately, I couldn't find a solution.

The only way to eliminate the delay is to define all routes statically. This can be done either in the blog.routes.ts file or through routes.txt.

@michaelhunziker
Copy link

Ok we are trying to create a minimal reproduction to report an issue.

@alan-agius4
Copy link
Contributor

alan-agius4 commented Apr 25, 2024

Likely your are using prerendering for non-parameterized routes.
You can find more information about this issue at: #55529 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: server Issues related to server-side rendering needs reproduction This issue needs a reproduction in order for the team to investigate further
Projects
None yet
Development

No branches or pull requests

6 participants