Skip to content

fix(ui): tab conditions not syncing to client, broken for tabs in arrays #12400

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Dynogic
Copy link

@Dynogic Dynogic commented May 13, 2025

What?

Fixed an issue where tab conditions were being incorrectly applied across all tabs in an array, causing the last tab's condition to override all other tabs' visibility states.

Why?

This bug was causing incorrect tab visibility behavior, where tabs that should have been visible based on their own conditions were being hidden because they were inheriting the condition from the last tab in the array. This affected the user experience and could lead to users being unable to access content that should have been available to them.

How?

  • Modified how tab conditions are stored and read in the state

@Dynogic Dynogic changed the title Fix tab conditions not working when tabs are in an array fix(ui): tab conditions not working when tabs are in an array May 13, 2025
@paulpopus
Copy link
Contributor

Hi can you add an e2e test for this config please?

This file here contains the config with conditional tabs and the accompanying e2e file will have the tests https://github.com/payloadcms/payload/blob/main/test/fields/collections/Tabs/index.ts#L0-L1

The test should fail without your changes, thank you very much for this PR!

@paulpopus paulpopus self-requested a review May 15, 2025 16:52
@paulpopus paulpopus self-assigned this May 15, 2025
@Dynogic
Copy link
Author

Dynogic commented May 16, 2025

Hi Paul, thanks for your reply!

I’ve identified another issue: tab conditions calculated on the server via buildFromStateHandler are not merged into the client-side form state. This regression was introduced in the following PR: #12026. As a result, tab conditions are currently broken in the latest Payload release (v3.38.0 at the time of writing).

To address this, I’ve added an addedByServer flag to the tab state in addFieldStatePromise.ts, and I’ve updated my PR accordingly.

E2E tests are on the way. For context, I’m able to reliably reproduce the array issue within my project’s collections. It seems the bug only manifests when one of the tab field’s ancestors also has a condition applied—this forces React to re-render all tabs, which is where the issue surfaces.

@Dynogic
Copy link
Author

Dynogic commented May 16, 2025

A quick update on the E2E tests: without the addedByServer flag, writing E2E tests for the new form state tab paths isn't effective—tests will fail both before and after the fix. This is because addedByServer is essential for restoring correct tab behavior. That said, we can write E2E tests to cover this bug, but they will continue to fail until addedByServer is fixed. Let me know how you'd like to proceed.

@Dynogic Dynogic changed the title fix(ui): tab conditions not working when tabs are in an array fix(ui): tab conditions not syncing to client, broken for tabs in arrays May 16, 2025
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