Skip to content

Commit

Permalink
Fix dependency loop with statustracker and markdown (#8821)
Browse files Browse the repository at this point in the history
* fix loop

* add changeset

* add changeset

* format

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
  • Loading branch information
3 people authored Jul 17, 2024
1 parent e1a4040 commit cea3bf9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/swift-ghosts-spend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/statustracker": patch
"gradio": patch
---

feat:Fix dependency loop with statustracker and markdown
3 changes: 2 additions & 1 deletion js/statustracker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"@gradio/atoms": "workspace:^",
"@gradio/icons": "workspace:^",
"@gradio/utils": "workspace:^",
"@gradio/markdown": "workspace:^"
"dompurify": "^3.0.3",
"@types/dompurify": "^3.0.2"
},
"devDependencies": {
"@gradio/preview": "workspace:^"
Expand Down
23 changes: 21 additions & 2 deletions js/statustracker/static/ToastContent.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { Error, Info, Warning } from "@gradio/icons";
import { MarkdownCode } from "@gradio/markdown";
import DOMPurify from "dompurify";
import { createEventDispatcher, onMount } from "svelte";
import { fade } from "svelte/transition";
import type { ToastMessage } from "./types";
Expand All @@ -11,6 +11,25 @@
export let duration: number | null = 10;
export let visible = true;
const is_external_url = (link: string | null): boolean => {
try {
return !!link && new URL(link, location.href).origin !== location.origin;
} catch (e) {
return false;
}
};
DOMPurify.addHook("afterSanitizeAttributes", function (node) {
if ("target" in node) {
if (is_external_url(node.getAttribute("href"))) {
node.setAttribute("target", "_blank");
node.setAttribute("rel", "noopener noreferrer");
}
}
});
$: message = DOMPurify.sanitize(message);
$: display = visible;
$: duration = duration || null;
Expand Down Expand Up @@ -56,7 +75,7 @@
<div class="toast-details {type}">
<div class="toast-title {type}">{type}</div>
<div class="toast-text {type}">
<MarkdownCode {message} chatbot={false} render_markdown={false} />
{@html message}
</div>
</div>

Expand Down
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cea3bf9

Please sign in to comment.