Skip to content

Copy shared assets when a symlink cannot be created - #7962

Open
DanShinde wants to merge 4 commits into
reflex-dev:mainfrom
DanShinde:fix-shared-asset-symlink-fallback
Open

DanShinde wants to merge 4 commits into
reflex-dev:mainfrom
DanShinde:fix-shared-asset-symlink-fallback

Conversation

@DanShinde

@DanShinde DanShinde commented Nov 22, 2026 •

Copy link
Copy Markdown

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Description

rx.asset(..., shared=True) links the asset into assets/external/ with a symlink. Where a symlink cannot be created (Windows without Developer Mode / the symlink privilege, or a filesystem without symlink support), symlink_to raises OSError and the app fails to compile, so any library using shared assets blocks reflex run.

_link_shared_asset now falls back to copying the asset when the symlink cannot be created. The copy goes through the same staged temp file and atomic replace as the link, so concurrent compiles stay safe, and the Windows replace-denied concession accepts an identical copy just as it accepts the same link. An existing copy with identical contents is left untouched, so file watchers see no change on recompile; a copy is rewritten when the source changes.

Tests: three new unit tests in tests/units/assets/test_assets.py (copy when symlinks are denied, up to date copy left alone, stale copy refreshed). They fail on main and pass with the change; the whole file passes (32 tests). ruff and pyright are clean. Changelog fragment added under news/.

Closes #5997

View guided diff

rx.asset(shared=True) links the asset into assets/external/ with a
symlink. On Windows without the symlink privilege, or on a filesystem
without symlink support, creating it raises OSError and the app cannot
compile. Fall back to copying the asset through the same staged
replace, and leave an up to date copy alone so file watchers see no
change.

Fixes reflex-dev#5997
@DanShinde
DanShinde requested a review from a team as a code owner November 22, 2026 07:15
@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous .tmp cleanup issue is fixed.

Summary

Shared assets fall back to copies when symlinks are unavailable.

  • Shared assets still load when symlinks are unavailable.
  • Startup cleanup removes copied assets after their sources disappear.

No new actionable issues were found.

Reviews (4) · Last reviewed commit: "Stage copy records outside the records d..." · Reviewed by Greptile

Comment thread reflex/assets.py Resolved
Comment thread reflex/assets.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread reflex/assets.py Resolved
Comment thread reflex/assets.py Resolved
Comment thread reflex/assets.py Resolved
- Compare a fallback copy with its source byte by byte instead of with
  filecmp, whose cache misses a rewrite that keeps size and mtime.
- When a replace is denied, accept the asset in place as either a link
  or a copy, so a concurrent compile that had to copy does not fail one
  that can link.
- Record the source of each fallback copy under the web directory and
  remove copies whose source is gone, as broken symlinks already are.
Comment thread reflex/assets.py Resolved
Comment thread reflex/assets.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread reflex/assets.py Resolved
Comment thread reflex/assets.py Resolved
Comment thread reflex/assets.py Resolved
- Treat a record replace that Windows denies as done when the record
  already names the same source, and log rather than raise otherwise,
  since the record only enables cleanup.
- Skip records still being staged under a temporary name, and tolerate
  records that disappear while cleanup runs.
- Re-read a stale record just before deleting its copy, so a copy that
  a concurrent compile made from a new source is kept.
Comment thread reflex/assets.py Resolved
Skipping every record named *.tmp also skipped records of real shared
assets with that suffix, so their copies were never cleaned up. Stage
records in a sibling directory instead, which cleanup never scans.

This branch has not been deployed

No deployments
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.

If creating a symlink fails, reflex cannot start

1 participant