Skip to content

Conversation

@djhi
Copy link
Collaborator

@djhi djhi commented Nov 5, 2025

Problem

When users are redirected to a list page for which they previously applied some parameters (page, perPage, filters, etc.), they don't see those parameters reflected in the URL even though they are indeed applied on the list. This happens for instance when redirected from an edition page. This makes the URL non shareable anymore and can be surprising.

Fixes #11018

Solution

When the list loads, if there are stored parameters and those are not reflected in the URL, update the URL except if:

  • the URL contains any parameters
  • disableSyncLocation is true
  • the parameters are the default ones (we want to keep clean and simple URLs such as /posts)

How To Test

  1. make run
  2. Apply some parameters on the list (filters, sort, perPage and/or page)
  3. Edit a post and save
  4. Check the URL is updated according to the previously set parameters

Performances

  • on the next branch, repeat the steps above but enable the react profiler (devtool) before clicking Save at step 3. Note the number of renders of the List component
  • do the same on this PR branch and compare with the previous number of renders

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The documentation is up to date

Also, please make sure to read the contributing guidelines.

@djhi djhi added RFR Ready For Review WIP Work In Progress and removed RFR Ready For Review labels Nov 5, 2025
) {
return;
}
navigate({
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised that this doesn't add a new entry in the history.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually it does, fix incoming

@fzaninotto
Copy link
Member

Why are all the packages.json updated?

@djhi
Copy link
Collaborator Author

djhi commented Jan 27, 2026

Why are all the packages.json updated?

Probably my editor, reverting

@djhi djhi force-pushed the better-list-url-management branch from ccd5b2b to 22a9fab Compare January 27, 2026 08:17
Comment on lines 164 to 167
// or the stored params are different from the location params
isEqual(query, queryFromLocation) ||
// or the stored params are not different from the default params (to keep the URL simple when possible)
isEqual(query, defaultParams)
Copy link
Member

Choose a reason for hiding this comment

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

The comments are describing the opposite condition as the code, so they're confusing.

Suggested change
// or the stored params are different from the location params
isEqual(query, queryFromLocation) ||
// or the stored params are not different from the default params (to keep the URL simple when possible)
isEqual(query, defaultParams)
// or the stored params are the same as the location params
isEqual(query, queryFromLocation) ||
// or the stored params are the same as the default params (to keep the URL simple when possible)
isEqual(query, defaultParams)

}
);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Member

Choose a reason for hiding this comment

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

If you remove this, the linter asks for 2 missing dependencies: queryFromLocation and storeKey. It seems legit to run this effect when these params change. Why did you choose to ignore them?

});
});

it('should not synchronize location with store if the store parameters are the defaults', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Could you also add a test with default params set by Component? Something like <Component perPage={5} sort={{ field: 'title', order: 'DESC' }} /> and then check that if the store contains the same values, the location will still be the default with no search param?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added below

}}
>
<CoreAdminContext dataProvider={testDataProvider()}>
<Component disableSyncWithLocation />
Copy link
Member

Choose a reason for hiding this comment

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

you should remove the disableSyncWithLocation otherwise you're not testing the right thing.

},
})}
>
<Component disableSyncWithLocation />
Copy link
Member

Choose a reason for hiding this comment

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

Remove disableSyncWithLocation here

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

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

3 participants