Skip to content

Fix url refresh after filter - #1298

Open
llsm wants to merge 1 commit into
contributte:masterfrom
llsm:fix-url-refresh-on-filter
Open

Fix url refresh after filter#1298
llsm wants to merge 1 commit into
contributte:masterfrom
llsm:fix-url-refresh-on-filter

Conversation

@llsm

@llsm llsm commented Jul 27, 2026

Copy link
Copy Markdown

The latest version does not update the URL in the browser after filtering. This change fixes it.

URL refresh isn't working in my project, nor in the demo at https://examples.contributte.org/datagrid-skeleton/.

@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.09%. Comparing base (ab5506d) to head (0663ef3).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/Datagrid.php 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1298      +/-   ##
==========================================
- Coverage   49.12%   49.09%   -0.04%     
==========================================
  Files          63       63              
  Lines        2974     2976       +2     
==========================================
  Hits         1461     1461              
- Misses       1513     1515       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@radimvaculik radimvaculik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging into this — the diagnosis is correct.

Historically the URL refresh was done in JS: the old assets/datagrid.js had a datagrid.url extension that reacted to payload._datagrid_url, rebuilt the URL from payload.state and called history.replaceState(). That extension was lost in the TS rewrite (dca24b4) — today _datagrid_url only exists in assets/types/ajax.d.ts, nothing consumes it. Hence the regression.

Delegating to Naja is the right call (HistoryHandler.pushNewState() does if (payload.postGet && payload.url) options.href = payload.url), and it matches what handleEdit() already does. Three things I'd like to resolve before merging:

1. It breaks setRefreshUrl(false)

The new lines are unconditional, so $this->refreshURL becomes meaningless (nothing reads _datagrid_url anymore). It needs to be guarded:

$this->getPresenterInstance()->payload->_datagrid_url = $this->refreshURL;
$this->getPresenterInstance()->payload->_datagrid_name = $this->getFullName();

if ($this->refreshURL) {
    $this->getPresenterInstance()->payload->postGet = true;
    $this->getPresenterInstance()->payload->url = $this->link('this');
}

2. Only one of the code paths is fixed

_datagrid_url is still sent (uselessly) from four other places:

  • reloadTheWholeGrid() — used by handleSort(), handleResetFilter(), handleResetColumnFilter(). This one is worse than "URL not updated": those are GET ajax links, so Naja pushes the signal URL (?do=grid-sort&…) into history.
  • handleGetChildren()
  • redrawItem()
  • handleRefreshState() — a method whose only purpose is "Simply refresh url", currently a no-op.

Could you extract this into a small private helper and call it from all of them, so it doesn't drift apart again?

3. Behavioural change: pushState instead of replaceState

The old JS used replaceState. Naja with the default history: true does pushState, so with filter autosubmit (debounced, assets/plugins/features/autosubmit.ts) every few keystrokes adds a history entry and the Back button walks through intermediate filter states. One-line fix in src/templates/datagrid.latte:

{form filter, class => 'ajax', data-naja-history => 'replace', data-naja-unique => "datagrid-filter-{$control->getFullName()}"}

Minor: handleEdit() already sets postGet/url unconditionally, i.e. it ignores refreshURL too — worth unifying via the same helper. The failing codecov/patch check isn't a blocker here.

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

Successfully merging this pull request may close these issues.

2 participants