Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): asset URLs re-mint per revision and before expiry without effects #24970

Mergedjuliusmarmingemerged 5 commits intomain fromrefs/pull/24970/headmerged by juliusmarminge View on GitHub

Showing 7 changed files with 186 additions and 3 deletions (loading 5).

x
0 of 7 viewed, 7 left
107 additions and 0 deletionsapps/web/src/assets/assetUrls.test.tsAdded
View file
@@ -0,0 +1,107 @@
+import { EnvironmentId, ThreadId, type AssetResource } from "@t3tools/contracts";
+import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
+import { describe, expect, it } from "vite-plus/test";
+​
+import { makeRevisionedAssetUrlFamily } from "./assetUrls";
+​
+const environmentId = EnvironmentId.make("environment-1");
+const resource: AssetResource = {
+ _tag: "workspace-file",
+ threadId: ThreadId.make("thread-1"),
+ path: "docs/diagram.png",
+};
+​
+type MintResult = AsyncResult.AsyncResult<{ relativeUrl: string; expiresAt: number }>;
+​
+const minted = (n: number): MintResult =>
+ AsyncResult.success({ relativeUrl: `/a/${n}`, expiresAt: 0 });
+​
+// A stand-in for the asset URL query: a refresh starts a mint (counted, shown as
+// waiting) and `settle` completes the latest one.
+function setup(initial: MintResult) {
+ let mints = 0;
+ // Node removal runs on the registry's scheduler; `unmount` flushes it so the
+ // next mount of the same revision builds a fresh node.
+ const scheduled: Array<() => void> = [];
+ const registry = AtomRegistry.make({
+ scheduleTask: (task) => {
+ scheduled.push(task);
+ return () => {};
+ },