Skip to content

Commit 35aae4e

Browse files
znationclaudegradio-pr-bot
authored
Add conditional padding for HF Space dashboard when not in iframe (#405)
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
1 parent a289d1b commit 35aae4e

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

.changeset/young-words-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trackio": minor
3+
---
4+
5+
feat:Add conditional padding for HF Space dashboard when not in iframe

trackio/ui/main.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -627,31 +627,59 @@ def configure(request: gr.Request):
627627
return null;
628628
}
629629
630-
(function() {
630+
(async function() {
631631
const urlParams = new URLSearchParams(window.location.search);
632632
const writeToken = urlParams.get('write_token');
633633
const footerParam = urlParams.get('footer');
634-
634+
635635
if (writeToken) {
636636
setCookie('trackio_write_token', writeToken, 7);
637-
638-
// Only remove write_token from URL if not in iframe
639-
// In iframes, keep it in URL as cookies may be blocked
637+
640638
const inIframe = window.self !== window.top;
641639
if (!inIframe) {
642640
urlParams.delete('write_token');
643-
const newUrl = window.location.pathname +
644-
(urlParams.toString() ? '?' + urlParams.toString() : '') +
641+
const newUrl = window.location.pathname +
642+
(urlParams.toString() ? '?' + urlParams.toString() : '') +
645643
window.location.hash;
646644
window.history.replaceState({}, document.title, newUrl);
647645
}
648646
}
649-
647+
650648
if (footerParam === 'false') {
651649
const style = document.createElement('style');
652650
style.textContent = 'footer { display: none !important; }';
653651
document.head.appendChild(style);
654652
}
653+
654+
const inIframe = window.self !== window.top;
655+
const isHfSpace = window.location.hostname.endsWith('.hf.space');
656+
657+
const waitForElement = function(selector) {
658+
return new Promise(resolve => {
659+
if (document.querySelector(selector)) {
660+
return resolve(document.querySelector(selector));
661+
}
662+
663+
const observer = new MutationObserver(mutations => {
664+
if (document.querySelector(selector)) {
665+
observer.disconnect();
666+
resolve(document.querySelector(selector));
667+
}
668+
});
669+
670+
observer.observe(document.body, {
671+
childList: true,
672+
subtree: true
673+
});
674+
});
675+
};
676+
if (isHfSpace && !inIframe) {
677+
document.querySelector('gradio-app').style.paddingTop = '56px';
678+
const spaceHeaderCollapseButton = await waitForElement('#space-header__collapse');
679+
spaceHeaderCollapseButton.addEventListener('click', function() {
680+
document.querySelector('gradio-app').style.paddingTop = '0px';
681+
});
682+
}
655683
})();
656684
</script>
657685
"""
@@ -1290,4 +1318,5 @@ def render_grouped_runs(project, group_key, filter_text, selection):
12901318
footer_links=["gradio", "settings"],
12911319
show_error=True,
12921320
ssr_mode=False,
1321+
head=HEAD,
12931322
)

0 commit comments

Comments
 (0)