Skip to content
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

fix(headless, atomic): ensure components are enabled/disabled correctly when an invalid tab id is provided #4944

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

fpbrault
Copy link
Contributor

@fpbrault fpbrault commented Feb 6, 2025

This PR ensures that when providing an invalid tab value, the active tab correctly falls back to the first available tab, with the tab-specific components enabled/disabled based on which tab is active.

https://coveord.atlassian.net/browse/KIT-3945

Copy link

github-actions bot commented Feb 6, 2025

Pull Request Report

PR Title

❌ Title should follow the conventional commit spec:
<type>(optional scope): <description>

Example: feat(headless): add result-list controller

Live demo links

Bundle Size

File Old (kb) New (kb) Change (%)
case-assist 246.6 246.6 0
commerce 359.2 359.3 0
search 417.3 417.3 0
insight 408.5 408.7 0.1
recommendation 258 258 0
ssr 411.1 411.1 0
ssr-commerce 375.7 375.8 0

@fpbrault fpbrault marked this pull request as ready for review February 19, 2025 15:58
@fpbrault fpbrault requested a review from a team as a code owner February 19, 2025 15:58
@fpbrault fpbrault requested a review from a team as a code owner February 19, 2025 19:48
Comment on lines -62 to -64
if (!validateParams(engine, newParams)) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why remove the validation ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not needed anymore, we fallback to the first tab automatically when an invalid tab value is provided.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This validates the ENTIRE SearchParameters, not just the tab parameter no?

We shouldn't remove the validation, we should only if possible, remove the validation of tabs only.

Copy link
Collaborator

@erocheleau erocheleau left a comment

Choose a reason for hiding this comment

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

Not sure I fully understand the scope of this, seems like there are changes that might "break" some things? See comments

@@ -84,6 +87,7 @@ export interface SearchParameters {

/**
* The active tab id.
* @deprecated restore the tab using the `restoreTab` action instead.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is the "Active tab id" in the SearchParameters being deprecated and suggested to use the restoreTab action?

These two things don't seem to do the same thing?


export const restoreTab = createAction(
'searchParameters/restoreTab',
(payload: string) => validatePayload(payload, requiredNonEmptyString)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would either create a RestoreTabPayload type, or name this something specific like tabId.

Just payload: string is not descriptive enough.

activateTabIfIdExists(state, id);
updateActiveTab(id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

So we were essentially calling updateActiveTab(id) twice?

Once through activateTabIfIdExists(state, id); and once directly through updateActiveTab(id) ?

@@ -22,10 +22,9 @@ export const tabSetReducer = createReducer(
const id = action.payload;
activateTabIfIdExists(state, id);
})
.addCase(restoreSearchParameters, (state, action) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So was this not used anywhere?

It's kinda weird that we can simply remove an action from a reducer and just be done with it?

@@ -19,14 +19,6 @@ routes.forEach((route) => {
.as('initial-results');
});

it('should add the tab search parameter with the default value', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why exactly is this being changed?

dispatch(registerTab({id, expression}));

const isFirstTab = Object.keys(engine.state.tabSet).length === 1;
if (isFirstTab) {
initialState.isActive = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't this create the situation if you originally load with a tab in the URL state t=something that the first tab will be triggered as active, and then afterwards when the urlManager does its thing that the real tab we want will get selected?

Comment on lines -62 to -64
if (!validateParams(engine, newParams)) {
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This validates the ENTIRE SearchParameters, not just the tab parameter no?

We shouldn't remove the validation, we should only if possible, remove the validation of tabs only.

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.

4 participants