Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[PdfHighlight]: broken ui issues in safari #28

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions frontend/src/components/ChatReferenceDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ const ChatReferenceDrawer = ({
filename,
onCancel,
}: IProps) => {
const file_url =
project_id && filename
? `${BASE_STORAGE_URL}/${project_id}/${filename}`
: null;
if (!filename) {
console.error("Filename is required to display the reference");
let file_url = null;
if (isOpen) {
file_url =
project_id && filename
? `${BASE_STORAGE_URL}/${project_id}/${filename}`
: null;
if (!filename) {
console.error("Filename is required to display the reference");
}
}

return (
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/components/ui/ChatBubble.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState, useCallback } from "react";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import rehypeSanitize from "rehype-sanitize";
import { markify_text } from "@/lib/utils";
import { ChatReference, ChatReferences } from "@/interfaces/chat";
Expand Down Expand Up @@ -132,10 +131,7 @@ const ChatBubble: React.FC<ChatBubbleProps> = ({
onReferenceClick={handleReferenceClick}
/>
) : (
<ReactMarkdown
remarkPlugins={[remarkGfm]}
rehypePlugins={[rehypeSanitize]}
>
<ReactMarkdown rehypePlugins={[rehypeSanitize]}>
{markify_text(message)}
</ReactMarkdown>
)}
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/components/ui/MessageWithReferences.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import rehypeSanitize from "rehype-sanitize";
import { ChatReference, ChatReferences } from "@/interfaces/chat";
import TooltipWrapper from "./Tooltip";
Expand All @@ -27,7 +26,6 @@ const MessageWithReferences: React.FC<MessageWithReferencesProps> = ({
parts.push(
<React.Fragment key={`text-${index}`}>
<ReactMarkdown
remarkPlugins={[remarkGfm]}
rehypePlugins={[rehypeSanitize]}
components={{
p: ({ children }) => <span>{children}</span>,
Expand Down Expand Up @@ -62,7 +60,6 @@ const MessageWithReferences: React.FC<MessageWithReferencesProps> = ({
parts.push(
<React.Fragment key="text-final">
<ReactMarkdown
remarkPlugins={[remarkGfm]}
rehypePlugins={[rehypeSanitize]}
components={{
p: ({ children }) => <span>{children}</span>,
Expand Down
18 changes: 17 additions & 1 deletion frontend/src/ee/components/HighlightPdfViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,23 @@ const HighlightPdfViewer: React.FC<PdfViewerProps> = ({

useEffect(() => {
if (typeof window !== "undefined") {
pdfjs.GlobalWorkerOptions.workerSrc = `/pdf.worker.mjs`;
if (typeof Promise.withResolvers === "undefined") {
if (window)
// @ts-expect-error This does not exist outside of polyfill which this is doing
window.Promise.withResolvers = function () {
let resolve, reject;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
return { promise, resolve, reject };
};
}

pdfjs.GlobalWorkerOptions.workerSrc = new URL(
"pdfjs-dist/legacy/build/pdf.worker.min.mjs",
import.meta.url
).toString();
}
}, []);

Expand Down
Loading