Skip to content

fix(js-client): fallback to space.version for cache version - #508

Open
intellix wants to merge 1 commit into
storyblok:mainfrom
intellix:space-version-update
Open

fix(js-client): fallback to space.version for cache version#508
intellix wants to merge 1 commit into
storyblok:mainfrom
intellix:space-version-update

Conversation

@intellix

@intellix intellix commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

The way that new versions are discovered today, is that it checks for data.cv and saves it in-memory. The problem is, the only way that data.cv is available, is through heavily cached endpoints. The cdn/spaces/me endpoint is only cached for 2 seconds and has a small response and includes the latest known version, but it's not used at all, until this PR.

With this change it'll allow me to poll the cdn/spaces/me endpoint every 60 seconds and switch back to querying for published content using the SDK.

Addressed the findings from this comment: #105 (comment)

@intellix

intellix commented Mar 16, 2026

Copy link
Copy Markdown
Contributor Author

pnpm patch for anyone that needs this now (me, but sharing anyway):

for 4.4.4:

patches/@storyblok__js.patch

diff --git a/dist/storyblok-js.mjs b/dist/storyblok-js.mjs
index 15130c1b6351bcc429d08afc3052b21af4201dbd..ca9ecc87a3a482efdf66dda0ecd983f42a22ac37 100644
--- a/dist/storyblok-js.mjs
+++ b/dist/storyblok-js.mjs
@@ -822,7 +822,8 @@ var $e = class {
         }
         t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i, E);
         const T = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
-        return t.token && E.data.cv && (T && S[t.token] && S[t.token] !== E.data.cv && await this.flushCache(), S[t.token] = E.data.cv), c(E);
+        const cv = E.data.cv || E.data.space?.version;
+        return t.token && cv && (T && S[t.token] && S[t.token] !== cv && await this.flushCache(), S[t.token] = cv), c(E);
       } catch (R) {
         if (R.response && R.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
           return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await Re(this.retriesDelay), this.cacheResponse(e, t, r).then(c).catch(b);

@intellix

intellix commented Apr 3, 2026

Copy link
Copy Markdown
Contributor Author

We needed to update our patch:

4.4.5

diff --git a/dist/storyblok-js.mjs b/dist/storyblok-js.mjs
index 1402bc6791e638e2e94573ca6e98d8b2cec2487d..a69fb4062e3babd362cdce651a0b06624e9779db 100644
--- a/dist/storyblok-js.mjs
+++ b/dist/storyblok-js.mjs
@@ -817,7 +817,8 @@ var Me = class {
         }
         t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i, A);
         const T = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
-        return t.token && A.data.cv && (T && S[t.token] && S[t.token] !== A.data.cv && await this.flushCache(), S[t.token] = A.data.cv), c(A);
+        const cv = A.data.cv || A.data.space?.version;
+        return t.token && cv && (T && S[t.token] && S[t.token] !== cv && await this.flushCache(), S[t.token] = cv), c(A);
       } catch (R) {
         if (R.response && R.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
           return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await pe(this.retriesDelay), this.cacheResponse(e, t, r).then(c).catch(b);

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.

1 participant