Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstated cacheBuster to new-client #1324

Merged
merged 4 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 new-client/public/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<!DOCTYPE html>
<html lang="sv">
<head>
Expand All @@ -13,6 +14,7 @@
<meta name="%REACT_APP_NAME%-build-date" content="%REACT_APP_BUILD_DATE%" />
<meta name="%REACT_APP_NAME%-git-hash" content="%REACT_APP_GIT_HASH%" />
<meta name="%REACT_APP_NAME%-version" content="%REACT_APP_VERSION%" />
<meta name="%REACT_APP_NAME%-use-cache-buster" content="%REACT_APP_USE_CACHE_BUSTER%" />

<link
rel="manifest"
Expand Down
18 changes: 14 additions & 4 deletions new-client/src/utils/FetchWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ class FetchWrapper {
this.options = {};

// Hash is used for cacheBuster function.
//this.hash = process?.env?.REACT_APP_GIT_HASH || null;
this.hash = null;
//this.useCacheBuster = process?.env?.REACT_APP_USE_CACHE_BUSTER === "true" || false;
this.useCacheBuster = false;
// Lets get the values from generated meta-tags
this.hash = this.getMetaValue("hajk-client-git-hash") || "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be sure that the meta tag will always be called hajk-client-use-cache-buster? I mean, it's created during build time by parsing %REACT_APP_NAME%-use-cache-buster, so another value on REACT_APP_NAME will break this completely.

this.useCacheBuster =
this.getMetaValue("hajk-client-use-cache-buster") === "true"
? true
: false;
}

matchesUrlPart(url, ruleWithWildCard) {
Expand All @@ -57,6 +59,14 @@ class FetchWrapper {
).test(url);
}

getMetaValue(key) {
const el = document.getElementsByName(key);
if (el && el[0]) {
return el[0]?.attributes?.content?.value;
}
return null;
}

Copy link
Member

@jacobwod jacobwod Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary, wouldn't something like this be more sufficient and work on all modern browsers anyway?

document.querySelector("meta[name='hajk-client-use-cache-buster']").getAttribute("content");

That oneliner on line 43 would be enough.

applyOptionOverrides() {
if (!this.partKeys) {
this.partKeys = Object.keys(this.config.hfetch.optionOverrides || {});
Expand Down