WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 95fdbe4

Browse files
Update cloud.js
1 parent 2ed49ae commit 95fdbe4

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

components/blocks/cloud.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef } from "react";
1+
import React, { useEffect, useRef, useState } from "react";
22
import classNames from "classnames";
33

44
// Arguments:
@@ -34,17 +34,18 @@ import classNames from "classnames";
3434
// -> https://foo.streamlit.app/bar/?embed=true&embed_options=show_padding&embed_options=show_colored_line
3535
//
3636
const Cloud = ({ name, path, query, height, domain, stylePlaceholder }) => {
37-
// Get the current theme embed option directly (with SSR safety)
38-
const getThemeEmbedOption = () => {
39-
if (typeof document !== "undefined") {
40-
return document.documentElement.classList.contains("dark")
41-
? "embed_options=dark_theme"
42-
: "embed_options=light_theme";
43-
}
44-
return "embed_options=light_theme"; // Default fallback for SSR
45-
};
37+
// State to track theme, starts with light theme for SSR
38+
const [themeEmbedOption, setThemeEmbedOption] = useState(
39+
"embed_options=light_theme",
40+
);
4641

47-
const themeEmbedOption = getThemeEmbedOption();
42+
// Update theme after component mounts (client-side only)
43+
useEffect(() => {
44+
const currentTheme = document.documentElement.classList.contains("dark")
45+
? "embed_options=dark_theme"
46+
: "embed_options=light_theme";
47+
setThemeEmbedOption(currentTheme);
48+
}, []);
4849

4950
if (!domain) domain = `${name}.streamlit.app`;
5051
if (domain.endsWith("/")) domain = domain.slice(0, -1);
@@ -56,32 +57,26 @@ const Cloud = ({ name, path, query, height, domain, stylePlaceholder }) => {
5657
path = "";
5758
}
5859

59-
let normalQueryStr = "";
60-
let embedQueryStr = "";
61-
6260
// Separate "normal" query params from "embed-related" query params.
6361
// This way we can include only the "normal" query params in the Fullscreen link.
6462
// Note that this only applies to iframes rendered via the <Cloud> component
6563
// in React. For iframes rendered via the ".. output::" directive we **always**
6664
// include any provided query param in the Fullscreen link.
67-
if (query) {
68-
const embedQueryParams = [];
69-
const normalQueryParams = [];
65+
const embedQueryParams = [themeEmbedOption];
66+
const normalQueryParams = [];
7067

68+
if (query) {
7169
query.split("&").forEach((qStr) => {
7270
if (qStr.startsWith("embed=") || qStr.startsWith("embed_options=")) {
7371
embedQueryParams.push(qStr);
7472
} else {
7573
normalQueryParams.push(qStr);
7674
}
7775
});
78-
79-
embedQueryStr = "&" + embedQueryParams.join("&");
80-
normalQueryStr = "&" + normalQueryParams.join("&");
8176
}
8277

83-
// Add theme parameter to embed query string
84-
embedQueryStr += `&${themeEmbedOption}`;
78+
const embedQueryStr = "&" + embedQueryParams.join("&");
79+
const normalQueryStr = "&" + normalQueryParams.join("&");
8580

8681
if (!height) height = "10rem";
8782

0 commit comments

Comments
 (0)