-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix(trace): Allow zip files of other mime types on paste #37907
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,50 +23,48 @@ import { DialogToolbarButton } from '@web/components/dialogToolbarButton'; | |
| import { Dialog } from '@web/shared/dialog'; | ||
| import { DefaultSettingsView } from './defaultSettingsView'; | ||
| import { TraceModelContext } from './traceModelContext'; | ||
| import { getMimeTypeForPath } from '@isomorphic/mimeType'; | ||
|
|
||
| export const WorkbenchLoader: React.FunctionComponent<{ | ||
| }> = () => { | ||
| const [isServer, setIsServer] = React.useState<boolean>(false); | ||
| const [traceURL, setTraceURL] = React.useState<string>(); | ||
| const [uploadedTraceName, setUploadedTraceName] = React.useState<string>(); | ||
| const [model, setModel] = React.useState<MultiTraceModel>(emptyModel); | ||
| const [progress, setProgress] = React.useState<{ done: number, total: number }>({ done: 0, total: 0 }); | ||
| const [dragOver, setDragOver] = React.useState<boolean>(false); | ||
| const [processingErrorMessage, setProcessingErrorMessage] = React.useState<string | null>(null); | ||
| const [fileForLocalModeError, setFileForLocalModeError] = React.useState<string | null>(null); | ||
| const [showProgressDialog, setShowProgressDialog] = React.useState<boolean>(false); | ||
|
|
||
| const processTraceFiles = React.useCallback((files: FileList) => { | ||
| const url = new URL(window.location.href); | ||
| if (!files.length) | ||
| const processTraceFiles = React.useCallback((files?: FileList | null) => { | ||
| if (!files?.length) | ||
| return; | ||
| const file = files.item(0)!; | ||
|
|
||
| // Do best effort to select the first valid trace valid, if not, rely on error reporting of sw | ||
| // Zip files may have different mime types on different operating systems, so rely on filename instead | ||
| const file = Array.from(files).find(file => getMimeTypeForPath(file.name) === 'application/zip') ?? files[0]; | ||
| const blobTraceURL = URL.createObjectURL(file); | ||
|
|
||
| const url = new URL(window.location.href); | ||
| url.searchParams.append('trace', blobTraceURL); | ||
| const href = url.toString(); | ||
| // Snapshot loaders will inherit the trace url from the query parameters, | ||
| // so set it here. | ||
| window.history.pushState({}, '', href); | ||
| setTraceURL(blobTraceURL); | ||
| setUploadedTraceName(file.name); | ||
| setDragOver(false); | ||
| setProcessingErrorMessage(null); | ||
| }, []); | ||
|
|
||
| React.useEffect(() => { | ||
| const listener = async (e: ClipboardEvent) => { | ||
| if (!e.clipboardData?.files.length) | ||
| return; | ||
| for (const file of e.clipboardData.files) { | ||
| if (file.type !== 'application/zip') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd just add application/x-zip-compressed for old Windows systems. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not just for old windows systems, I am experiencing this mime-type behaviour on Windows 11. |
||
| return; | ||
| } | ||
| e.preventDefault(); | ||
| processTraceFiles(e.clipboardData.files); | ||
| processTraceFiles(e.clipboardData?.files); | ||
| }; | ||
| document.addEventListener('paste', listener); | ||
| return () => document.removeEventListener('paste', listener); | ||
| }); | ||
|
|
||
| React.useEffect(() => { | ||
| const listener = (e: MessageEvent) => { | ||
| const { method, params } = e.data; | ||
|
|
@@ -90,11 +88,9 @@ export const WorkbenchLoader: React.FunctionComponent<{ | |
| processTraceFiles(event.dataTransfer.files); | ||
| }, [processTraceFiles]); | ||
|
|
||
| const handleFileInputChange = React.useCallback((event: any) => { | ||
| const handleFileInputChange = React.useCallback((event: Event) => { | ||
| event.preventDefault(); | ||
| if (!event.target.files) | ||
| return; | ||
| processTraceFiles(event.target.files); | ||
| processTraceFiles((event.target as HTMLInputElement).files); | ||
| }, [processTraceFiles]); | ||
|
|
||
| React.useEffect(() => { | ||
|
|
@@ -157,7 +153,7 @@ export const WorkbenchLoader: React.FunctionComponent<{ | |
| navigator.serviceWorker.removeEventListener('message', swListener); | ||
| } | ||
| })(); | ||
| }, [isServer, traceURL, uploadedTraceName]); | ||
| }, [isServer, traceURL]); | ||
|
|
||
| const showLoading = progress.done !== progress.total && progress.total !== 0 && !processingErrorMessage; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pasting multiple files looks like a user error, we can bail sooner or leave it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It definitely is a user error. However, why not try to find/load the valid trace file from this fileslist? I think that's preferable over not showing anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this regresses users that renamed their traces to foo.trace, what do we do to those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
However, in this case we just try to find the first
.zipfile, if not found it will just pick the first one and send it to the server to handle (possibly returning an error). So, processing will just work fine for them. It is just that those users don't 'benefit' from this 'best effort'