Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

A preview wrapper rewritten gets its own bundle: a dot-named edit is part of its bundle cache key. The cache names a bundle by every source file under the edit's folder, but its walk passes dot files over, and the app's preview wrappers (.raea-view-NAME.tsx) are dot files rewritten at one path. A wrapper naming a model's new light level was given the bundle that named the old one, so the stage asked for a copy the store had dropped (the 3D didn't open) or drew the model as it was before an edit. Keys of other edits are unchanged. 1 test; docs/preview.feature PV3b has the packaged low-disk run.

shinyobjectzb6aa8b1d1e7a
diff --git a/docs/preview.feature b/docs/preview.feature
index 85e74e37..89ab6491 100644
--- a/docs/preview.feature
+++ b/docs/preview.feature
@@ -109,6 +109,12 @@ Feature: Preview: anything in a project opens at once, in its space, with its pr
# every copy, the first rule, emptied it); Clear leaves no file. Checked there: 23 copies, 13.7 MB, to 6.8 MB at a
# 7.5 MB limit; a light level kept over a 3 MB limit while its model played and gone a minute later with the
# stills left; a changed source's copy marked stale and swept; Clear from 18 files to none. 10 tests.
+ # 11-09, 0.1.0-dev.1109.25: with the store told its disk had 500 MB free, 45 heavy models opened in seven seconds
+ # took it to 294 MB (every copy in use), and the next model opened a minute later left 39 copies in 255 MB, the
+ # oldest seven gone. The same pass found a model's preview drawn from another run's bundle: the wrapper
+ # (.raea-view-NAME.tsx) is rewritten at one path and the bundle cache's folder walk passes dot files over, so a
+ # wrapper naming a new light level got the bundle naming the old one (a level since dropped: "doesn't exist").
+ # A dot-named edit is now part of its bundle's key.
@done
Scenario: PV3b. The store is managed in one place
Then Settings lists the store by project and kind with sizes, and offers Clear and Rebuild; copies whose source
diff --git a/runtime/bundle/src/cache.rs b/runtime/bundle/src/cache.rs
index 36c1ba8c..0fceb178 100644
--- a/runtime/bundle/src/cache.rs
+++ b/runtime/bundle/src/cache.rs
@@ -165,6 +165,11 @@ pub fn bundle_cache(tsx: &Path, o: &CompOpts) -> Option<PathBuf> {
let js = raea_io_home::home().join("sdk/react/js");
let mut files = Vec::new();
walk(tsx.parent()?, 0, &mut files);
+ // the edit itself when its name starts with a dot, which the walk passes over (the app's preview wrappers,
+ // .raea-view-NAME.tsx, are rewritten at one path: without this a rewritten one got the bundle of the last)
+ if file_is_hidden(tsx) {
+ files.extend(stat(tsx).map(|(n, t)| (tsx.to_path_buf(), n, t)));
+ }
// what it imports from outside its folder (outside.rs): editing an example re-bundles what imports it
for o in outside(tsx.parent()?).unwrap_or_default() {
files.extend(stat(&o.file).map(|(n, t)| (o.file, n, t)));
@@ -200,6 +205,10 @@ pub fn bundle_cache(tsx: &Path, o: &CompOpts) -> Option<PathBuf> {
Some(root.join(format!("{key:016x}.js")))
}
+fn file_is_hidden(p: &Path) -> bool {
+ p.file_name().is_some_and(|n| n.to_string_lossy().starts_with('.'))
+}
+
/// The newest `keep` files with extension `ext` in `dir` kept, by when they were last written or used.
pub fn prune_cache(dir: &Path, ext: &str, keep: usize) {
// a write that never finished (its process killed between the copy and the rename) goes after an hour
diff --git a/runtime/bundle/src/tests.rs b/runtime/bundle/src/tests.rs
index be589420..9a55ada8 100644
--- a/runtime/bundle/src/tests.rs
+++ b/runtime/bundle/src/tests.rs
@@ -70,3 +70,20 @@ fn outside_copies_what_the_edit_imports_beyond_its_folder() {
assert!(e.contains("lib/c.ts") && e.contains("outside raea's home"), "{e}");
std::fs::remove_dir_all(&t).unwrap();
}
+
+#[test]
+fn a_dot_named_edit_rewritten_gets_another_bundle() {
+ // the app's preview wrapper (.raea-view-NAME.tsx) is rewritten at one path, and the folder walk passes dot files over
+ let t = std::env::temp_dir().join(format!("raea-bundle-dot-{}", std::process::id()));
+ std::fs::create_dir_all(&t).unwrap();
+ let o = comp_opts(&[]).unwrap();
+ let (hidden, plain) = (t.join(".raea-view-body.tsx"), t.join("body.tsx"));
+ std::fs::write(&hidden, "export const a = 1\n").unwrap();
+ std::fs::write(&plain, "export const a = 1\n").unwrap();
+ let (first, other) = (bundle_cache(&hidden, &o).unwrap(), bundle_cache(&plain, &o).unwrap());
+ std::fs::write(&hidden, "export const a = 22\n").unwrap();
+ assert_ne!(bundle_cache(&hidden, &o).unwrap(), first);
+ // a file the walk sees is counted once, as before
+ assert_eq!(bundle_cache(&plain, &o).unwrap(), other);
+ std::fs::remove_dir_all(&t).unwrap();
+}