Skip to content

Commit

Permalink
feat: implement cache-busting with version parameter to ensure screen…
Browse files Browse the repository at this point in the history
… updates are reflected

- Added a version parameter to screen URLs based on the last modified id.
- Ensures that changes in the screen trigger a new URL, bypassing cached versions.
- Prevents stale data by forcing the browser to fetch the updated resource when changes occur.
  • Loading branch information
eiresendez committed Sep 27, 2024
1 parent a576745 commit 44b8058
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/DataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export default {
const hasIncludeScreen = params.match(/include=.*,screen,/);
const hasIncludeNested = params.match(/include=.*,nested,/);

// Extract screen_version from params.
const screenVersionMatch = params.match(/screen_version=([^&]+)/);
const screenVersion = screenVersionMatch ? screenVersionMatch[1] : "";

// remove params ?...
promises.push(
this.get(endpoint + params.replace(/,screen,|,nested,/g, ","))
Expand All @@ -90,7 +94,7 @@ export default {
const screenEndpoint = `${(endpoint + params).replace(
/\?.+$/,
""
)}/screen?include=screen${hasIncludeNested ? ",nested" : ""}`;
)}/screen?include=screen${hasIncludeNested ? ",nested" : ""}&screen_version=${screenVersion}`;
promises.push(this.get(screenEndpoint));
}
// Await for both promises to resolve
Expand Down
3 changes: 2 additions & 1 deletion src/components/task.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default {
initialRequestId: { type: Number, default: null },
initialProcessId: { type: Number, default: null },
initialNodeId: { type: String, default: null },
screenVersion: { type: Number, default: null },
userId: { type: Number, default: null },
csrfToken: { type: String, default: null },
value: { type: Object, default: () => {} },
Expand Down Expand Up @@ -265,7 +266,7 @@ export default {
return;
}
const url = `/${this.taskId}?include=data,user,draft,requestor,processRequest,component,screen,requestData,loopContext,bpmnTagName,interstitial,definition,nested,userRequestPermission,elementDestination`;
const url = `/${this.taskId}?include=data,user,draft,requestor,processRequest,component,screen,requestData,loopContext,bpmnTagName,interstitial,definition,nested,userRequestPermission,elementDestination&screen_version=${this.screenVersion}`;
// For Vocabularies
if (window.ProcessMaker && window.ProcessMaker.packages && window.ProcessMaker.packages.includes('package-vocabularies')) {
window.ProcessMaker.VocabulariesSchemaUrl = `vocabularies/task_schema/${this.taskId}`;
Expand Down

0 comments on commit 44b8058

Please sign in to comment.