fix(js-client): fallback to space.version for cache version - #508
Open
intellix wants to merge 1 commit into
Open
fix(js-client): fallback to space.version for cache version#508intellix wants to merge 1 commit into
intellix wants to merge 1 commit into
Conversation
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);
|
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)