Skip to content

Commit 9a86e80

Browse files
Fix Login Gradio 6 (#12461)
* Fix * add changeset * Fix Changesets Updated dependency versions for various Gradio components and fixed the login issue in Gradio 6. --------- Co-authored-by: gradio-pr-bot <[email protected]>
1 parent e0764fd commit 9a86e80

File tree

6 files changed

+82
-51
lines changed

6 files changed

+82
-51
lines changed

.changeset/six-clouds-love.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@gradio/core": patch
3+
"@gradio/form": patch
4+
"@self/app": patch
5+
"@self/spa": patch
6+
"gradio": patch
7+
---
8+
9+
fix:Fix Login Gradio 6

js/app/src/routes/[...catchall]/+page.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import { _ } from "svelte-i18n";
8282
import { Client } from "@gradio/client";
8383
import { page } from "$app/stores";
84+
import { setupi18n } from "@gradio/core";
8485
8586
import { init } from "@huggingface/space-header";
8687
import { browser } from "$app/environment";
@@ -240,19 +241,22 @@
240241
let pending_deep_link_error = false;
241242
242243
let gradio_dev_mode = "";
244+
let i18n_ready = false;
245+
setupi18n().then(() => {
246+
i18n_ready = true;
247+
});
243248
244249
onMount(async () => {
245250
//@ts-ignore
246251
config = data.config;
247-
window.gradio_config = config;
248252
window.gradio_config = data.config;
249253
config = data.config;
250254
251255
if (config.deep_link_state === "invalid") {
252256
pending_deep_link_error = true;
253257
}
254258
255-
if (!app.config) {
259+
if (!app?.config && !config.auth_required) {
256260
throw new Error("Could not resolve app config");
257261
}
258262
@@ -415,6 +419,7 @@
415419
root={config.root}
416420
space_id={space}
417421
{app_mode}
422+
i18n={i18n_ready ? $_ : (s) => s}
418423
/>
419424
{:else if config && app}
420425
<svelte:component

js/core/src/Login.svelte

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<script lang="ts">
2-
import Form from "@gradio/form";
2+
import { BaseForm } from "@gradio/form";
33
import { BaseTextbox as Textbox } from "@gradio/textbox";
44
import { BaseButton } from "@gradio/button";
5-
import Column from "@gradio/column";
5+
import { BaseColumn } from "@gradio/column";
66
import { Block } from "@gradio/atoms";
7-
import { _ } from "svelte-i18n";
87
export let root: string;
98
export let auth_message: string | null;
109
export let app_mode: boolean;
1110
export let space_id: string | null;
11+
export let i18n: (s: string) => string;
1212
1313
let username = "";
1414
let password = "";
@@ -34,23 +34,23 @@
3434
</script>
3535

3636
<div class="wrap" class:min-h-screen={app_mode}>
37-
<Column variant="panel" min_width={480}>
38-
<h2>{$_("login.login")}</h2>
37+
<BaseColumn variant="panel" min_width={480}>
38+
<h2>{i18n("login.login")}</h2>
3939
{#if auth_message}
4040
<p class="auth">{@html auth_message}</p>
4141
{/if}
4242
{#if space_id}
4343
<p class="auth">
44-
{$_("login.enable_cookies")}
44+
{i18n("login.enable_cookies")}
4545
</p>
4646
{/if}
4747
{#if incorrect_credentials}
48-
<p class="creds">{$_("login.incorrect_credentials")}</p>
48+
<p class="creds">{i18n("login.incorrect_credentials")}</p>
4949
{/if}
50-
<Form>
50+
<BaseForm>
5151
<Block>
5252
<Textbox
53-
label={$_("login.username")}
53+
label={i18n("login.username")}
5454
lines={1}
5555
show_label={true}
5656
max_lines={1}
@@ -61,7 +61,7 @@
6161

6262
<Block>
6363
<Textbox
64-
label={$_("login.password")}
64+
label={i18n("login.password")}
6565
lines={1}
6666
show_label={true}
6767
max_lines={1}
@@ -70,12 +70,12 @@
7070
bind:value={password}
7171
/>
7272
</Block>
73-
</Form>
73+
</BaseForm>
7474

7575
<BaseButton size="lg" variant="primary" on:click={submit}
76-
>{$_("login.login")}</BaseButton
76+
>{i18n("login.login")}</BaseButton
7777
>
78-
</Column>
78+
</BaseColumn>
7979
</div>
8080

8181
<style>

js/form/BaseForm.svelte

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<script lang="ts">
2+
let { visible, scale, min_width } = $props();
3+
</script>
4+
5+
<div
6+
class="form"
7+
class:hidden={visible === false}
8+
class:hidden-css={visible === "hidden"}
9+
style:flex-grow={scale}
10+
style:min-width={`calc(min(${min_width}px, 100%))`}
11+
>
12+
<slot />
13+
</div>
14+
15+
<style>
16+
div {
17+
display: flex;
18+
flex-direction: inherit;
19+
flex-wrap: wrap;
20+
gap: var(--form-gap-width);
21+
box-shadow: var(--block-shadow);
22+
border: var(--block-border-width) solid var(--block-border-color);
23+
border-radius: var(--block-radius);
24+
background: var(--border-color-primary);
25+
overflow-y: hidden;
26+
}
27+
28+
div :global(.block) {
29+
box-shadow: none !important;
30+
border-width: 0px !important;
31+
border-radius: 0px !important;
32+
}
33+
34+
.hidden {
35+
display: none;
36+
}
37+
38+
.hidden-css {
39+
display: none !important;
40+
}
41+
</style>

js/form/Index.svelte

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,19 @@
1+
<script context="module" lang="ts">
2+
export { default as BaseForm } from "./BaseForm.svelte";
3+
</script>
4+
15
<script lang="ts">
26
import { Gradio } from "@gradio/utils";
7+
import BaseForm from "./BaseForm.svelte";
38
49
let props = $props();
510
const gradio = new Gradio(props);
611
</script>
712

8-
<div
9-
class="form"
10-
class:hidden={gradio.shared.visible === false}
11-
class:hidden-css={gradio.shared.visible === "hidden"}
12-
style:flex-grow={gradio.shared.scale}
13-
style:min-width={`calc(min(${gradio.shared.min_width}px, 100%))`}
13+
<BaseForm
14+
visible={gradio.shared.visible}
15+
scale={gradio.shared.scale}
16+
min_width={gradio.shared.min_width}
1417
>
1518
<slot />
16-
</div>
17-
18-
<style>
19-
div {
20-
display: flex;
21-
flex-direction: inherit;
22-
flex-wrap: wrap;
23-
gap: var(--form-gap-width);
24-
box-shadow: var(--block-shadow);
25-
border: var(--block-border-width) solid var(--block-border-color);
26-
border-radius: var(--block-radius);
27-
background: var(--border-color-primary);
28-
overflow-y: hidden;
29-
}
30-
31-
div :global(.block) {
32-
box-shadow: none !important;
33-
border-width: 0px !important;
34-
border-radius: 0px !important;
35-
}
36-
37-
.hidden {
38-
display: none;
39-
}
40-
41-
.hidden-css {
42-
display: none !important;
43-
}
44-
</style>
19+
</BaseForm>

js/spa/src/Index.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@
330330
app.close();
331331
});
332332
333-
if (!app.config) {
333+
if (!app.config && !config?.auth_required) {
334334
throw new Error("Could not resolve app config");
335335
}
336336
@@ -587,6 +587,7 @@
587587
auth_message={config.auth_message}
588588
root={config.root}
589589
space_id={space}
590+
i18n={i18n_ready ? $_ : (s: string) => s}
590591
{app_mode}
591592
/>
592593
{:else if config && Blocks && css_ready}

0 commit comments

Comments
 (0)