@@ -35,6 +35,7 @@ export function SourcePanel({ docAndNode, doCopy, doDownload, doImport, copySucc
35
35
const download = useRef < HTMLAnchorElement > ( null )
36
36
const retransform = useRef < Function > ( ( ) => { } )
37
37
const onImport = useRef < ( ) => Promise < void > > ( async ( ) => { } )
38
+ const outputRef = useRef < string > ( )
38
39
39
40
const textarea = useRef < HTMLTextAreaElement > ( null )
40
41
const editor = useRef < Editor > ( )
@@ -56,6 +57,7 @@ export function SourcePanel({ docAndNode, doCopy, doDownload, doImport, copySucc
56
57
}
57
58
try {
58
59
const output = getSerializedOutput ( text )
60
+ outputRef . current = output
59
61
editor . current . setValue ( output )
60
62
} catch ( e ) {
61
63
if ( e instanceof Error ) {
@@ -163,22 +165,22 @@ export function SourcePanel({ docAndNode, doCopy, doDownload, doImport, copySucc
163
165
} , [ indent , format , sort , highlighting , braceLoaded ] )
164
166
165
167
useEffect ( ( ) => {
166
- if ( doCopy && text !== undefined ) {
167
- navigator . clipboard . writeText ( getSerializedOutput ( text ) ) . then ( ( ) => {
168
+ if ( doCopy && outputRef . current ) {
169
+ navigator . clipboard . writeText ( outputRef . current ) . then ( ( ) => {
168
170
copySuccess ( )
169
171
} )
170
172
}
171
- } , [ doCopy , text ] )
173
+ } , [ doCopy , textarea ] )
172
174
173
175
useEffect ( ( ) => {
174
- if ( doDownload && docAndNode && text !== undefined && download . current ) {
175
- const content = encodeURIComponent ( getSerializedOutput ( text ) )
176
+ if ( doDownload && docAndNode && outputRef . current && download . current ) {
177
+ const content = encodeURIComponent ( outputRef . current )
176
178
download . current . setAttribute ( 'href' , `data:text/json;charset=utf-8,${ content } ` )
177
179
const fileName = fileUtil . basename ( docAndNode . doc . uri )
178
180
download . current . setAttribute ( 'download' , fileName )
179
181
download . current . click ( )
180
182
}
181
- } , [ doDownload ] )
183
+ } , [ doDownload , outputRef ] )
182
184
183
185
useEffect ( ( ) => {
184
186
if ( doImport && editor . current ) {
0 commit comments