Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,8 +1495,8 @@ impl Project {

/// Computes the whole app module graph without dropping issues.
///
/// Use this instead of [`whole_app_module_graphs`] when you need to collect issues from the
/// computation (e.g. for the `get_compilation_issues` MCP tool).
/// Use this instead of [Self::whole_app_module_graphs] when you need to collect issues from
/// the computation (e.g. for the `get_compilation_issues` MCP tool).
#[turbo_tasks::function]
pub async fn whole_app_module_graphs_without_dropping_issues(
self: ResolvedVc<Self>,
Expand Down
2 changes: 2 additions & 0 deletions crates/next-napi-bindings/src/next_api/turbopack_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ pub fn create_turbo_tasks(
}),
dependency_tracking,
num_workers: Some(tokio::runtime::Handle::current().metrics().num_workers()),
evict_after_snapshot: std::env::var("TURBO_ENGINE_EVICT_AFTER_SNAPSHOT")
.is_ok_and(|v| v == "1" || v == "true"),
..Default::default()
},
Either::Left(backing_storage),
Expand Down
91 changes: 91 additions & 0 deletions test/e2e/filesystem-cache/evict-after-snapshot.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { nextTestSetup, isNextDev } from 'e2e-utils'
import { retry, waitFor } from 'next-test-utils'

// Eviction requires the dev server (HMR) and persistent caching (Turbopack).
// Skip entirely in prod/start mode.
Comment thread
lukesandberg marked this conversation as resolved.
;(isNextDev ? describe : describe.skip)('evict-after-snapshot', () => {
const envVars = [
'ENABLE_CACHING=1',
'TURBO_ENGINE_IGNORE_DIRTY=1',
'TURBO_ENGINE_SNAPSHOT_IDLE_TIMEOUT_MILLIS=1000',
'TURBO_ENGINE_EVICT_AFTER_SNAPSHOT=1',
].join(' ')

const { skipped, next } = nextTestSetup({
files: __dirname,
skipDeployment: true,
packageJson: {
scripts: {
dev: `${envVars} next dev`,
},
},
installCommand: 'npm i',
startCommand: 'npm run dev',
})

if (skipped) {
Comment thread
lukesandberg marked this conversation as resolved.
return
}

async function waitForSnapshotAndEviction() {
// The idle timeout is 1s, give extra time for snapshot + eviction to complete
await waitFor(5000)
}

// Turbopack-only: eviction requires persistent caching
;(process.env.IS_TURBOPACK_TEST ? it : it.skip)(
'should serve correct content after eviction and HMR',
async () => {
const browser = await next.browser('/')
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('hello world')
})

let currentContent = 'hello world'
for (let cycle = 1; cycle <= 3; cycle++) {
await waitForSnapshotAndEviction()

const prevContent = currentContent
const nextContent = `cycle ${cycle}`
await next.patchFile('app/page.tsx', (content) =>
content.replace(prevContent, nextContent)
)
currentContent = nextContent

const expected = currentContent
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe(expected)
}, 10000)
}

await browser.close()
},
90000
)
;(process.env.IS_TURBOPACK_TEST ? it : it.skip)(
'should handle client component HMR after eviction',
async () => {
const browser = await next.browser('/client')
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('hello world')
})

await waitForSnapshotAndEviction()

await next.patchFile(
'app/client/page.tsx',
(content) => content.replace('hello world', 'hello eviction'),
async () => {
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe(
'hello eviction'
)
}, 10000)
}
)

await browser.close()
},
90000
)
})
3 changes: 1 addition & 2 deletions turbopack/crates/turbo-persistence/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,7 @@ impl<S: ParallelScheduler, const FAMILIES: usize> TurboPersistence<S, FAMILIES>

/// Clears all caches of the database.
pub fn clear_cache(&self) {
self.key_block_cache.clear();
self.value_block_cache.clear();
self.clear_block_caches();
for meta in self.inner.write().meta_files.iter_mut() {
meta.clear_cache();
}
Expand Down
8 changes: 8 additions & 0 deletions turbopack/crates/turbo-tasks-auto-hash-map/src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ impl<K: Hash + Eq, H: BuildHasher + Default, const I: usize> AutoSet<K, H, I> {
pub fn contains(&self, key: &K) -> bool {
self.map.contains_key(key)
}

/// see [HashSet::retain](https://doc.rust-lang.org/std/collections/hash_set/struct.HashSet.html#method.retain)
pub fn retain<F>(&mut self, mut f: F)
where
F: FnMut(&K) -> bool,
{
self.map.retain(|k, _| f(k));
}
}

impl<K, H, const I: usize> AutoSet<K, H, I> {
Expand Down
2 changes: 2 additions & 0 deletions turbopack/crates/turbo-tasks-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ turbo-persistence = { workspace = true }
turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true }
turbo-tasks-hash = { workspace = true }
turbo-tasks-malloc = { workspace = true, default-features = false }
thread_local = { workspace = true }

[dev-dependencies]
Expand All @@ -68,6 +69,7 @@ futures = { workspace = true }
indoc = { workspace = true }
regex = { workspace = true }
tempfile = { workspace = true }
triomphe = { workspace = true }
turbo-tasks-malloc = { workspace = true }
rstest = { workspace = true }
turbo-tasks-testing = { workspace = true }
Expand Down
Loading
Loading