GeezerVison is showing github.com — [DevTools] [Profiler]: Save profile now working in Firefox (#16612) · react/react@77bb102
File treeExpand file treeCollapse file tree Open diff view settings packages/react-devtools-shared/src/devtools/views
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/devtools/views/Profiler/ProfilingImportExportButtons.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,7 @@ export default function ProfilingImportExportButtons() { | 29 | 29 | const {profilerStore} = store; | 30 | 30 |
| 31 | 31 | const inputRef = useRef<HTMLInputElement | null>(null); | | 32 | + const downloadRef = useRef<HTMLAnchorElement | null>(null); | 32 | 33 |
| 33 | 34 | const {dispatch: modalDialogDispatch} = useContext(ModalDialogContext); | 34 | 35 |
| @@ -38,7 +39,7 @@ export default function ProfilingImportExportButtons() { | 38 | 39 | return; | 39 | 40 | } | 40 | 41 |
| 41 | | - if (profilingData !== null) { | | 42 | + if (profilingData !== null && downloadRef.current !== null) { | 42 | 43 | const profilingDataExport = prepareProfilingDataExport(profilingData); | 43 | 44 | const date = new Date(); | 44 | 45 | const dateString = date | @@ -54,6 +55,7 @@ export default function ProfilingImportExportButtons() { | 54 | 55 | }) | 55 | 56 | .replace(/:/g, '-'); | 56 | 57 | downloadFile( | | 58 | + downloadRef.current, | 57 | 59 | `profiling-data.${dateString}.${timeString}.json`, | 58 | 60 | JSON.stringify(profilingDataExport, null, 2), | 59 | 61 | ); | @@ -114,6 +116,7 @@ export default function ProfilingImportExportButtons() { | 114 | 116 | onChange={handleFiles} | 115 | 117 | tabIndex={-1} | 116 | 118 | /> | | 119 | + <a ref={downloadRef} className={styles.Input} /> | 117 | 120 | <Button | 118 | 121 | disabled={isProfiling} | 119 | 122 | onClick={uploadData} | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/devtools/views/utils.js +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -178,7 +178,11 @@ export function serializeHooksForCopy(hooks: HooksTree | null): string { | 178 | 178 | // Without this, we would see a "Download failed: network error" failure. | 179 | 179 | let downloadUrl = null; | 180 | 180 |
| 181 | | -export function downloadFile(filename: string, text: string): void { | | 181 | +export function downloadFile( | | 182 | + element: HTMLAnchorElement, | | 183 | + filename: string, | | 184 | + text: string, | | 185 | +): void { | 182 | 186 | const blob = new Blob([text], {type: 'text/plain;charset=utf-8'}); | 183 | 187 |
| 184 | 188 | if (downloadUrl !== null) { | @@ -187,15 +191,10 @@ export function downloadFile(filename: string, text: string): void { | 187 | 191 |
| 188 | 192 | downloadUrl = URL.createObjectURL(blob); | 189 | 193 |
| 190 | | - const element = document.createElement('a'); | 191 | 194 | element.setAttribute('href', downloadUrl); | 192 | 195 | element.setAttribute('download', filename); | 193 | | - element.style.display = 'none'; | 194 | | - ((document.body: any): HTMLBodyElement).appendChild(element); | 195 | 196 |
| 196 | 197 | element.click(); | 197 | | - | 198 | | - ((document.body: any): HTMLBodyElement).removeChild(element); | 199 | 198 | } | 200 | 199 |
| 201 | 200 | export function truncateText(text: string, maxLength: number): string { | |
|