Skip to content

Commit c5f6e77

Browse files
aliabid94Ali Abidgradio-pr-bot
authored
Cache break themes on change (#8499)
* changes * add changeset * changes * add changeset --------- Co-authored-by: Ali Abid <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]>
1 parent 2a59bab commit c5f6e77

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

.changeset/tall-keys-report.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@gradio/app": patch
3+
"@gradio/client": patch
4+
"gradio": patch
5+
---
6+
7+
feat:Cache break themes on change

client/js/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export interface Config {
173173
path: string;
174174
protocol: "sse_v3" | "sse_v2.1" | "sse_v2" | "sse_v1" | "sse" | "ws";
175175
max_file_size?: number;
176+
theme_hash?: number;
176177
}
177178

178179
// todo: DRY up types

globals.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ export interface Config {
3838
show_error: boolean;
3939
is_space: boolean;
4040
protocol: "ws" | "sse" | "sse_v1" | "sse_v2" | "sse_v2.1" | "sse_v3";
41+
theme_hash?: number;
4142
}

gradio/blocks.py

+5
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,10 @@ def __init__(
988988
self.theme: Theme = theme
989989
self.theme_css = theme._get_theme_css()
990990
self.stylesheets = theme._stylesheets
991+
theme_hasher = hashlib.sha256()
992+
theme_hasher.update(self.theme_css.encode("utf-8"))
993+
self.theme_hash = theme_hasher.hexdigest()
994+
991995
self.encrypt = False
992996
self.share = False
993997
self.enable_queue = True
@@ -2040,6 +2044,7 @@ def get_config_file(self):
20402044
),
20412045
},
20422046
"fill_height": self.fill_height,
2047+
"theme_hash": self.theme_hash,
20432048
}
20442049
config.update(self.default_config.get_config())
20452050
config["connect_heartbeat"] = utils.connect_heartbeat(

js/app/src/Index.svelte

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
path: string;
3030
app_id?: string;
3131
fill_height?: boolean;
32+
theme_hash?: number;
3233
}
3334
3435
let id = -1;
@@ -131,7 +132,10 @@
131132
css_text_stylesheet || undefined
132133
);
133134
}
134-
await mount_css(config.root + "/theme.css", document.head);
135+
await mount_css(
136+
config.root + "/theme.css?v=" + config.theme_hash,
137+
document.head
138+
);
135139
if (!config.stylesheets) return;
136140
137141
await Promise.all(

0 commit comments

Comments
 (0)