Fix entry-editor and entry-form refresh#322
Open
BogdanArdelean wants to merge 1 commit intopages-cms:mainfrom
Open
Fix entry-editor and entry-form refresh#322BogdanArdelean wants to merge 1 commit intopages-cms:mainfrom
BogdanArdelean wants to merge 1 commit intopages-cms:mainfrom
Conversation
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.
BogdanArdelean
commented
Oct 13, 2025
| 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); |
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
defaultValuesisn't reset to the newest version of the file.useFormcachesdefaultValuesas per the documentation.Changes
entry-editor.tsx:
fetchData.setEntry+setSha. This ensures the updated entryContentObject trickles down toentry-form.tsx.entry-form.tsx:
useEffectto reset the form’s default values when they change.fixed.webm