Skip to content

Conversation

@Abhishek022001
Copy link

Problem

When running dx components list or dx components add on a fresh setup (with no existing components), a failure during download or installation could leave a partially-created state under .dx/components/.

Specifically:

  • The components directory (and subdirectories) could be created
  • The operation fails before component.json is written
  • Subsequent runs then fail with os error 2 due to missing or incomplete manifests

This leaves the CLI in a broken state that requires manual cleanup.


Solution

This PR makes component installation atomic by introducing a validation-first, commit-later flow:

  • All filesystem operations are first performed in a temporary staging directory
  • No writes are made to the final .dx/components/<component> path until all validation succeeds
  • If any step fails, temporary files are automatically cleaned up
  • Final paths are only created via rename/move once success is guaranteed

As a result, failures no longer leave behind partial or corrupted state.


Why this is safe

  • Success-path behavior is unchanged
  • No public APIs were modified
  • Cleanup is automatic on error or early return
  • Prevents filesystem corruption across retries

Testing

  • Verified logic by exercising failure paths that previously caused partial .dx/components state
  • Confirmed no final component directories are created when operations fail early

@Abhishek022001 Abhishek022001 requested a review from a team as a code owner January 14, 2026 14:32
Copy link
Member

@ealmloff ealmloff left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, it would be useful to roll back changes if we run into an error, but I don't think these changes would do that.

All of the code in add_component should run after the component registry is already downloaded so the files this could potentially catch are all IO errors which could also be caused by the "atomic" commit the new code path does at the end.

To make this more atomic, we would need to:

  1. add a lock file for the components to make sure the registry and components folder are not being edited by two processes at the same
    time
  2. add logic to roll back changes in the Self::Add branch of the run function. There are other changes like adding dependencies we make outside of add_component

@jkelleyrtp jkelleyrtp added the cli Related to the dioxus-cli program label Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to the dioxus-cli program

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants