Skip to content

fix(core): prevent cached show page data in create forms#7475

Open
Woutuuur wants to merge 2 commits into
refinedev:mainfrom
athenagroup:fix/prevent-cached-show-page-data-in-create-forms
Open

fix(core): prevent cached show page data in create forms#7475
Woutuuur wants to merge 2 commits into
refinedev:mainfrom
athenagroup:fix/prevent-cached-show-page-data-in-create-forms

Conversation

@Woutuuur

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

When opening a create modal (useModalForm with action: "create") on a show page for the same resource, the form's defaultValues are overwritten by cached data from the show page's useOne query. This happens because useForm passes the URL-derived id to useOne even for create actions, causing a query key collision with the cached entry. The useModalForm visibility reset effect then calls reset() with the cached show-page data, replacing the user-provided defaultValues.

What is the new behavior?

  • core (useForm): id is no longer passed to useOne when the action is "create", preventing the cache key collision at the source.
  • react-hook-form (useModalForm): The visibility reset effect is guarded against "create" actions, so it never calls reset() with query data for create forms.

Create modal forms now correctly retain their defaultValues regardless of cached data from the same resource.

with cached show-page data when action is 'create'"
@changeset-bot

changeset-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fc27249

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Woutuuur Woutuuur force-pushed the fix/prevent-cached-show-page-data-in-create-forms branch from 06a468e to fc27249 Compare June 30, 2026 09:15
@abhishekchauhan1365

Copy link
Copy Markdown

This looks like a solid fix and the root cause is clearly addressed.

Avoiding passing the id to useOne for "create" actions makes sense and eliminates the cache key collision at the source. The additional safeguard in useModalForm to skip reset() for create flows is a good defensive layer as well.

The regression test is especially valuable here since this kind of issue can easily resurface with future changes.

One small thing to clarify:

  • Are there any edge cases where id might still be implicitly inferred (e.g., via URL params in custom setups) that could reintroduce similar collisions?

Otherwise, the approach is clean and well-scoped. Good to go from my side.

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