Skip to content

[LiveComponent] Non-writeable props that are exposed in the URL should not be added to the URL after an action #2651

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

Closed
jannes-io opened this issue Mar 23, 2025 · 2 comments
Labels

Comments

@jannes-io
Copy link
Contributor

jannes-io commented Mar 23, 2025

Scenario: We want a component where a property is passable through the URL, but is not included in the URL when actions are performed on the component.

So we create this component, expecting that if a prop isn't writeable, it should never be set in the URL unless we generate the URL for the user with that parameter included:

#[AsLiveComponent]
class MyComponent
{
    use DefaultActionTrait;

    #[LiveProp(writable: true, url: true)]
    public string $prop1;

    #[LiveProp(url: true)]
    public string $prop2 = 'default';

    #[LiveAction]
    public function doAction() {  /* not important */ }
}

Navigate to: /?prop1=hello

Perform the doAction

Current: the url updated to /?prop1=hello&prop2=default
Expected: the url remains /?prop1=hello

Workaround:
Mount a secondary custom stimulus controller on the live controller and remove the param again every time it updates. Sure, this works for a single component, but isn't a generic solution that can be applied to all parameters since we don't know about writability or even default values of the props in this controller.

@jannes-io jannes-io added the Bug Bug Fix label Mar 23, 2025
@jannes-io
Copy link
Contributor Author

After thinking about it, writability probably has nothing to do with it.

So would it be better as a feature? With the requirements being if the current value of a property is the same as the default value, or initial value on first render, do not include it in the URL parameters? It's mostly just for aesthetic reasons to keep the URL params limited to only the values that have changed.

@jannes-io
Copy link
Contributor Author

Duplicate of #2141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants