Application environment editor reverts to stale value after a successful save
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 37.4k
- Forks
- 3k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 73
Description
To Reproduce
- Open an Application → Environment.
- Change an existing value, for example
TIMEFRAME=15mtoTIMEFRAME=150m. - Save with Ctrl/Cmd+S.
- Immediately change it again, for example
TIMEFRAME=150mtoTIMEFRAME=151m, and save. - Observe the editor after the save and then refresh the page.
Current vs. Expected behavior
Current
The editor briefly shows the just-saved value, then reverts to the previous value. For example, after saving 151m, it can show 150m again. The caret also jumps to the first line when this happens.
A full page refresh shows the last value actually saved to the backend. In the example, after saving 151m → 15m, the editor can visually return to 151m, while refresh correctly shows 15m. This can cause a user to save the stale value again accidentally.
Expected
After a successful save, the editor must retain saved text and caret/scroll position. A polling response started before the mutation must not overwrite the saved form state.
Root cause
The application detail page polls application.one every 5 seconds:
apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/application/[applicationId].tsx
api.application.one.useQuery({ applicationId }, { refetchInterval: 5000 });
ShowEnvironment shares that query. PR #4626 correctly avoids resetting while the form is dirty, but its successful-save path calls form.reset(formData), which clears isDirty. A pre-save polling response may then resolve with old data; the effect accepts it because !isDirty and calls form.reset(...) again. This also recreates the CodeMirror document and moves the caret to line 1.
Proposed fix
Use api.useUtils() in ShowEnvironment and make saving mutation-safe:
await utils.application.one.cancel({ applicationId })before the mutation, so an in-flight poll cannot overwrite post-save state.- On success, update the cached
application.onerecord with saved environment fields viautils.application.one.setData(...). - Reset the form from that committed value, then invalidate/refetch for eventual server reconciliation.
- Add a regression test where a stale poll resolves after
saveEnvironment; it must not replace the committed editor value or reset caret position.
Environment
- Dokploy:
v0.30.5 - Deployment: self-hosted, same server as Dokploy
- Resource: Application, Dockerfile build
Will you send a PR to fix it?
Yes
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/application/[applicationId].tsx and trace ShowEnvironment’s application.one polling and saveEnvironment mutation. Add a regression test where a stale poll resolves after saving; done means the committed editor text and caret/scroll position remain unchanged, while the cache is reconciled with the backend.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100