Skip to content

Commit 447f470

Browse files
authored
feat: sync url for huggingface embeddings (#1547)
## Description Closes #1337 Added support for HuggingFace embedding by implementing URL parameter synchronization between parent and child windows. When the application is embedded in HuggingFace, it now emits location changes to the parent window, allowing proper URL state management. ## Related Issue and Pull requests ## Type of Change - [x] New feature ## Checklist - [x] I have tested this does not break current pipelines / runs functionality - [x] I have tested the changes on staging ## Test Instructions 1. [Screen Recording 2025-12-12 at 2.08.44 PM.mov <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.com/user-attachments/thumbnails/58ca40ef-b24d-41e4-974b-ef0bebd89380.mov" />](https://app.graphite.com/user-attachments/video/58ca40ef-b24d-41e4-974b-ef0bebd89380.mov) Go to https://huggingface.co/spaces/TangleML/tangle_test4 2. Verify that URL parameters and hash changes are properly synchronized between the parent and child windows ## Additional Comments This implementation follows the HuggingFace documentation for handling URL parameters in embedded Spaces: https://huggingface.co/docs/hub/en/spaces-handle-url-parameters
1 parent a107ac3 commit 447f470

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/routes/router.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,22 @@ export const router = createRouter({
124124
history,
125125
basepath: IS_GITHUB_PAGES ? "" : basepath, // Hash history doesn't need basepath
126126
});
127+
128+
if (import.meta.env.VITE_HUGGING_FACE_AUTHORIZATION === "true") {
129+
/**
130+
* Sync state from the parent window to the child window in HuggingFace embedding
131+
* @see https://huggingface.co/docs/hub/en/spaces-handle-url-parameters
132+
* @todo: think about making this as a plugin
133+
*/
134+
function emitLocationChange() {
135+
window.parent.postMessage(
136+
{
137+
queryString: window.location.search,
138+
hash: window.location.hash,
139+
},
140+
"https://huggingface.co",
141+
);
142+
}
143+
144+
router.subscribe("onRendered", emitLocationChange);
145+
}

0 commit comments

Comments
 (0)