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

Link to the current page doesn't contain all URL parameters #323

Closed
peterpp opened this issue Mar 19, 2024 · 7 comments
Closed

Link to the current page doesn't contain all URL parameters #323

peterpp opened this issue Mar 19, 2024 · 7 comments

Comments

@peterpp
Copy link

peterpp commented Mar 19, 2024

Version: 3.1.14 and probably all older

Bug Description

From the documentation:

The target this will create a link to the current page:

<a n:href="this">refresh</a>

At the same time, all parameters specified in the signature of the render<View>() or action<Action>() method are transferred.

This is not true if a presenter contains both render<View>() and action<Action>() methods with different parameters.

Steps To Reproduce

Presenter:

class HomePresenter: extends Nette\Application\UI\Presenter
{
    public function actionDefault(): void
    {
        //
    }

    public function renderDefault(?string $param = null): void
    {
        //
    }
}

Template:

<a n:href="this">refresh</a>

Web URL: https://www.someurl.com/?param=test
Now, generated link contains URL without parameter: https://www.someurl.com/

Expected Behavior

All parameters from both render* and action* methods should be transferred.

Current behavior is at least confusing and may led to broken service if somebody forget to keep exactly the same parameters in both methods.

@dg
Copy link
Member

dg commented Mar 19, 2024

I mean, the documentation says render<View>() OR action<Action>()

@peterpp
Copy link
Author

peterpp commented Mar 19, 2024

Yes, but human language is not a programming language with short-circuit evaluation. I have a black and white pencil and I say you: Choose black pencil or white pencil. Do I mean that you can't choose white pencil?

However, It is still quite unexpected and vulnerable to easily broke the application.

@dg
Copy link
Member

dg commented Mar 19, 2024

Do you have any suggestions on how to improve the documentation text?

@peterpp
Copy link
Author

peterpp commented Mar 19, 2024

I see that you are refusing to even consider or discuss that the code itself could be potentially improved and help developers to make less mistakes and keep their code simpler.

Documentation proposal:

At the same time, all parameters specified in the signature of the action<Action>() method or render<View>() method, if the action<Action>() is not defined, are transferred.

In Czech:

Zároveň se přenáší i všechny parametry uvedené v signatuře metody action<Action>() nebo metody render<View>(), pokud není action<Action>() definovaná.

@dg
Copy link
Member

dg commented Mar 19, 2024

I'm certainly not opposed to improvements, but I can't immediately think of a better way to do it, and at the same time, you're the first person in 15 years to deal with this, so I'm not seeing it as a priority. Even in light of the fact that I don't want to make BC breaks.

@peterpp
Copy link
Author

peterpp commented Mar 20, 2024

I understand such a change would be BC break and the priority is low. I also understand that creating unified signature for both actionX and renderX methods would be problematic – parameters can have different order, the same parameter can be optional in the first method and required in the second, they even can have different types theoretically.

What I do right now, is keeping parameters in both methods identical. Together with warning in comment to remind me that I have to keep parameters always the same. To be honest, after years of development in Nette, I'm quite tired of doing it this way. In one case, I have 10 parameters in actionX method and none of them are actually used. They are required just to force framework to create links properly.

Another solution is to write all parameters in template explicitly like this:

<a n:href="this param1 => true, param2 => true">refresh</a>

Not cool. In this approach I have to think about it in every single usage.

So let me propose another solution. I can imagine the setting that will control parameters rendering (in a similar way how autoCanonicalize can be changed). This setting will have options:

  • preferActionParams (default, current behavior)
  • preferRenderParams (much more useful in real scenarios, in my opinion)
  • unifyParams (universal, but maybe too complicated to implement)

@MartinMystikJonas
Copy link

Main problem here is that actionX does not always continue renderX. Rendering view X by renderX after actionX is default but actionX can freely choose what view it will render.

dg added a commit to nette/docs that referenced this issue Apr 6, 2024
dg added a commit to nette/docs that referenced this issue Apr 18, 2024
dg added a commit to nette/docs that referenced this issue May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants