Skip to content

fix(site): keep TemplateVersionEditor file tree in sync#25068

Merged
aslilac merged 2 commits into
mainfrom
lilac/fix-template-version-editor-file-state
Jun 26, 2026
Merged

fix(site): keep TemplateVersionEditor file tree in sync#25068
aslilac merged 2 commits into
mainfrom
lilac/fix-template-version-editor-file-state

Conversation

@aslilac

@aslilac aslilac commented May 7, 2026

Copy link
Copy Markdown
Member

The TemplateVersionEditor kept its own local copy of the file tree, while the page kept the initial copy loaded from the tar. Active path resolution ran against the page's stale tree, so creating a file fell back to the entrypoint and renaming threw File is not a text file from getFileText.

Lift file tree state up to TemplateVersionEditorPage so there is a single source of truth, and add regression tests for the create and rename flows.

Implementation plan

Symptoms

  1. Create: clicking the new file in the sidebar does not open it; the editor stays on the previous file.
  2. Rename: getFileText in filetree.ts throws "File is not a text file".

Root cause

fileTree lives in two places: TemplateVersionEditorPage (initial copy from tar) and TemplateVersionEditor (local mutable copy via useState(defaultFileTree)). The parent never sees the child's edits, so getActivePath validates against the parent's stale tree:

  • Create newfile.tf: child has it, parent does not. existsFile("newfile.tf", parentTree) is false, so the active path falls back to findEntrypointFile(parentTree) which is main.tf. The editor opens main.tf instead.
  • Rename main.tfapp.tf: child has app.tf only. The fallback returns main.tf from the parent, and the editor calls getFileText("main.tf", childTreeWithoutMainTf) which throws.

Fix

Lift the file tree state up to the page. useFileTree exposes a setFileTree, and TemplateVersionEditor takes fileTree and onFileTreeChange props instead of defaultFileTree.

Generated by Coder Agents.

The editor kept its own local copy of the file tree, while the page kept the
initial copy loaded from the tar. The page resolved the active path against
its stale tree, so creating a file fell back to the entrypoint and renaming
threw 'File is not a text file' from getFileText.

Lift the file tree state up to TemplateVersionEditorPage so there is a
single source of truth. Add regression tests for create and rename.

Generated by Coder Agents.
@github-actions github-actions Bot added the stale This issue is like stale bread. label May 18, 2026
@github-actions github-actions Bot closed this May 22, 2026
@aslilac aslilac reopened this Jun 25, 2026
@aslilac aslilac removed the stale This issue is like stale bread. label Jun 25, 2026
@aslilac aslilac marked this pull request as ready for review June 25, 2026 23:18
@aslilac aslilac merged commit 7481e1a into main Jun 26, 2026
53 of 75 checks passed
@aslilac aslilac deleted the lilac/fix-template-version-editor-file-state branch June 26, 2026 20:47
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants