X Tutup
Skip to content

Fix entry-editor and entry-form refresh#322

Open
BogdanArdelean wants to merge 1 commit intopages-cms:mainfrom
BogdanArdelean:issue/321-form-reset
Open

Fix entry-editor and entry-form refresh#322
BogdanArdelean wants to merge 1 commit intopages-cms:mainfrom
BogdanArdelean:issue/321-form-reset

Conversation

@BogdanArdelean
Copy link

@BogdanArdelean BogdanArdelean commented Oct 13, 2025

Addressing #321. I wanted to make a PR against develop, but it's behind main. Will update when develop is up to date.

The problem is that after submitting the changes, the form's defaultValues isn't reset to the newest version of the file. useForm caches defaultValues as per the documentation.

Changes

entry-editor.tsx:

  • Extracted the data-fetching logic into a separate function, fetchData.
  • After submitting the form, fetch the latest entry version and call setEntry + setSha. This ensures the updated entryContentObject trickles down to entry-form.tsx.

entry-form.tsx:

  • Added a useEffect to reset the form’s default values when they change.
fixed.webm

entry-editor.tsx:
- Extracted the data-fetching logic into a separate function, `fetchData`.
- After submitting the form, fetch the latest entry version and call `setEntry` + `setSha`.
  This ensures the updated entryContentObject trickles down to `entry-form.tsx`.

entry-form.tsx:
- Added a `useEffect` to reset the form’s default values when they change.
if (data.status !== "success") throw new Error(data.message);

if (data.data.sha !== sha) setSha(data.data.sha);
let remoteData = await fetchData(config.owner, config.repo, config.branch, savePath, name);
Copy link
Author

Choose a reason for hiding this comment

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

I think it’s necessary to call setEntry and setSha here, but I’m not sure if we really need to fetch the remote data.
In theory, we could just do setEntry(contentObject), at this point they should be identical, and we could drop the extra GET while embracing optimistic updates.

A cleaner and more REST-aligned approach would be for the POST to return the updated resource directly, which would eliminate the need for that extra GET.

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.

1 participant

X Tutup