question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve parameter-values

See original GitHub issue

Since Angular prerendering in general and angular-prerenderer specifially finally works for me, I now tried to care about the details. With no luck so far. It is great that angular-prerenderer offers the param parameter-values, but its usage is either not well documented or it doesn’t work for my scenario.

Consider these route definitions

const routes: Routes = [
    {
        path: "/bar",
        component: HomeComponent
    },
    {
        path: "/route-i-want-to-prerender/:id/:title",
        component: WhatEver
    },
    {
        path: "/route-i-do-not-want-to-prerender/:id/:title",
        component: AnotherOne,
    }
]

First problem: Params have the same name across routes, but there is just one route for which I want to pass params (or I want to pass different params per route). Second problem: There are multiple params per route. If I pass the params like '{":id":["1","2","3"],":title":["foo1","foo2","foo3"] I expect the routes below to be prerendered

  • /route-i-want-to-prerender/1/foo1
  • /route-i-want-to-prerender/2/foo2
  • /route-i-want-to-prerender/3/foo3

However, instead of 3 routes, angular-prerenderer produced 9. I don’t get exactly what happens here, but it is wrong for my use case.

Finally, I’d prefer to be able to pass a JSON file (or a path pointing to a JSON file, to be more precise) instead of a string. That way, you get rid of escaping problems and you won’t run into any length restriction issues on the command line.

In my opinion, the expected structure of that JSON file should be something like this

{
    "/route-i-want-to-prerender/:id/:title": [
        { ":id": "1", ":title": "foo1" },
        { ":id": "2", ":title": "foo2" },
        { ":id": "3", ":title": "foo3" }
    ],
    "/another-route-i-want-to-prerender/:id/:title": [
        { ":id": "4", ":title": "bar4" },
        { ":id": "5", ":title": "bar5" },
        { ":id": "6", ":title": "bar6" }
    ],
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisguttandincommented, Apr 1, 2020

Hi @cschwaderer,

thanks for filing this issue? Unfortunately the --parameter-values argument is not really usable for your use case. It currently renders each route with all possible permutations. And as you discovered the parameter values can’t be scoped to a specific route.

I like the schema that you proposed. Building up on this I would propose the following.

  • The current functionality keeps the same if you specify the JSON as this it will render 9 routes:
{
    ":id": ["1","2","3"],
    ":title": ["foo1","foo2","foo3"]
}
  • Additionally it should be possible to group parameters. This will only render 3 routes:
[
    {":id":["1"], ":title":["foo1"]},
    {":id":["2"], ":title":["foo2"]},
    {":id":["3"], ":title":["foo3"]}
]
  • And finally as you proposed it should be possible to scope parameters by routes:
{
    "/route-i-want-to-prerender/:id/:title": [
        { ":id": "1", ":title": "foo1" },
        { ":id": "2", ":title": "foo2" },
        { ":id": "3", ":title": "foo3" }
    ],
    "/another-route-i-want-to-prerender/:id/:title": [
        { ":id": "4", ":title": "bar4" },
        { ":id": "5", ":title": "bar5" },
        { ":id": "6", ":title": "bar6" }
    ],
}

This means a property of the JSON object can be either a parameter (":id") or a route ("/x/y/z"). If it starts with colon it’s considered to be a parameter and if it starts with a slash it’s considered to be a path.

The values must be either a string or an array of strings.

Does that sound reasonable to you?

0reactions
chrisguttandincommented, Apr 6, 2020

I’m glad it helps you.

Both of your examples should work. You could even get rid of a couple of more characters:

{
    "/route-i-want-to-prerender": [
        { ":id": "1", ":title": "foo1" },
        { ":id": "2", ":title": "foo2" },
        { ":id": "3", ":title": "foo3" }
    ],
    "/another-route-i-want-to-prerender": [
        { ":id": "4", ":title": "bar4" },
        { ":id": "5", ":title": "bar5" },
        { ":id": "6", ":title": "bar6" }
    ]
}

It’s only necessary to specify the portion of the route which is different from the others. I also allowed another schema to avoid the additional array in case there is only one set of parameter values per route. In that case you could use something like this…

{
    "/route-i-want-to-prerender": { ":id": "1", ":title": "foo1" },
    "/another-route-i-want-to-prerender": { ":id": "4", ":title": "bar4" }
}

Please let me know if that doesn’t work. In that case I introduced a bug.

Adding a JSON schema validation is an excellent idea. I’ll put it on the todo list.

I thought it makes the README simpler when I only use one parameter but I can see why that wasn’t a good idea. Thanks for your feedback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimisers: How to improve the current parameter values
Optimisers: How to improve the current parameter values¶. The optimiser varies the model parameters in an attempt to find the solution which minimises...
Read more >
Optimisers: How to improve the current parameter values
Optimisers: How to improve the current parameter values¶. The optimiser varies the model parameters in an attempt to find the solution which minimises...
Read more >
Understanding LightGBM Parameters (and How to Tune Them)
How to tune lightGBM parameters in python? ... Then Small max_bin causes faster speed and large value improves accuracy.
Read more >
Increasing Parameter Store throughput - AWS Systems Manager
The throughput setting applies to standard and advanced parameters. Topics. Configuring permissions to increase Parameter Store throughput ...
Read more >
NOCOPY Hint to Improve Performance of OUT and IN OUT ...
Oracle has two methods of passing passing OUT and IN OUT parameters in PL/SQL code: Pass By Value : The default action is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found