Skip to content

Add push history state support to LiveComponent#3550

Open
ajgarlag wants to merge 1 commit into
symfony:3.xfrom
ajgarlag:push-history-state
Open

Add push history state support to LiveComponent#3550
ajgarlag wants to merge 1 commit into
symfony:3.xfrom
ajgarlag:push-history-state

Conversation

@ajgarlag

Copy link
Copy Markdown
Q A
Bug fix? no
New feature? yes
Deprecations? no
Documentation? yes
Issues Fix #3149
License MIT

This PR adds support for pushing browser history entries when a LiveComponent updates URL-bound LiveProp values.

Until now, URL updates were always done with history.replaceState(), which overwrote the current entry. With this change, components can opt in to history.pushState() so users can navigate previous component states via the browser back button (for example, previous pages in pagination or prior filter states in search UIs).

Included changes:

  • Added a new pushHistoryState parameter to #[AsLiveComponent(...)] (default: false).
  • Exposed this option in component metadata as push_history_state.
  • Added LiveComponentMetadata::hasPushHistoryStateEnabled() to read the flag.
  • Updated LiveUrlSubscriber to include a new response header:
    • X-Live-Url-Push-History-State: 1|0
  • Updated frontend BackendResponse to parse the new header.
  • Updated frontend URL update logic to choose:
    • history.pushState(...) when enabled
    • history.replaceState(...) otherwise (current behavior preserved)

@carsonbot carsonbot added Documentation Improvements or additions to documentation Feature New Feature Status: Needs Review Needs to be reviewed labels May 19, 2026
@carsonbot carsonbot changed the title Add push history state support to LiveComponent Add push history state support to LiveComponent May 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📊 Packages dist files size difference

Thanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
Please review the changes and make sure they are expected.

FileBefore (Size / Gzip)After (Size / Gzip)
LiveComponent
live_controller.d.ts 7.54 kB / 1.96 kB 7.61 kB+1% 📈 / 1.98 kB+1% 📈
live_controller.js 82.56 kB / 18.35 kB 82.83 kB0% / 18.43 kB0%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Feature New Feature Status: Needs Review Needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LiveComponent] URL linked LiveProps don't seem to honour the browser back button

2 participants