-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
DataViews: Preserve filters when switching layouts in templates dataviews #67744
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +14 B (0%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
For me in trunk |
Flaky tests detected in a4dfbec. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12237385864
|
@@ -170,20 +185,16 @@ export default function PageTemplates() { | |||
[ postTypeActions, editAction ] | |||
); | |||
|
|||
const onChangeView = useCallback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why swap useCallback
with useEvent
?
Update: Should we always memoize this callback? If that's the case, maybe we should use useEvent
internally to make it easier for consumers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to generate a new callback instance if "view.type" changes or if "layout" changes or if "history" changes... We only want a stable reference that has access to all the latest props of the component.
useEvent
is great because it allows us to separate the "dependencies" of an effect from the actual code that needs to trigger as a result of that effect. We can control these two things separately leading to more clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it documented somewhere that this is how consumers should pass onChangeView
- with stable reference?
If DataView
cares about the onChangeView
reference, maybe it's better if we handle it there. Just a random thought I had when viewing the code. We can discuss and handle it separately.
const onChangeView = useEvent( onChangeViewProp );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a number of components in DataViews using memo
and using onChangeView
, so memoization is needed. Now, it's true that we can do it internally but useCallback
existed before this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Related #55083
What?
When switching layouts in the "templates" dataviews, the filters, sorting... is lost. This PR fixes that.
Pages dataviews suffer from the same issue and it's being fixed in #67740
Testing Instructions
1- Open the "templates" dataviews
2- Apply some random filter
3- Switch the layout
4- The filter should persist.