@@ -214,10 +214,20 @@ const initializeScene = async (opts: {
214
214
)
215
215
> => {
216
216
const searchParams = new URLSearchParams ( window . location . search ) ;
217
+ const hashParams = new URLSearchParams ( window . location . hash . slice ( 1 ) ) ;
217
218
const id = searchParams . get ( "id" ) ;
218
- const jsonBackendMatch = window . location . hash . match (
219
- / ^ # j s o n = ( [ a - z A - Z 0 - 9 _ - ] + ) , ( [ a - z A - Z 0 - 9 _ - ] + ) $ / ,
220
- ) ;
219
+ const shareableLink = hashParams . get ( "json" ) ?. split ( "," ) ;
220
+
221
+ if ( shareableLink ) {
222
+ hashParams . delete ( "json" ) ;
223
+ const hash = `#${ decodeURIComponent ( hashParams . toString ( ) ) } ` ;
224
+ window . history . replaceState (
225
+ { } ,
226
+ APP_NAME ,
227
+ `${ window . location . origin } ${ hash } ` ,
228
+ ) ;
229
+ }
230
+
221
231
const externalUrlMatch = window . location . hash . match ( / ^ # u r l = ( .* ) $ / ) ;
222
232
223
233
const localDataState = importFromLocalStorage ( ) ;
@@ -227,7 +237,7 @@ const initializeScene = async (opts: {
227
237
} = await loadScene ( null , null , localDataState ) ;
228
238
229
239
let roomLinkData = getCollaborationLinkData ( window . location . href ) ;
230
- const isExternalScene = ! ! ( id || jsonBackendMatch || roomLinkData ) ;
240
+ const isExternalScene = ! ! ( id || shareableLink || roomLinkData ) ;
231
241
if ( isExternalScene ) {
232
242
if (
233
243
// don't prompt if scene is empty
@@ -237,16 +247,16 @@ const initializeScene = async (opts: {
237
247
// otherwise, prompt whether user wants to override current scene
238
248
( await openConfirmModal ( shareableLinkConfirmDialog ) )
239
249
) {
240
- if ( jsonBackendMatch ) {
250
+ if ( shareableLink ) {
241
251
scene = await loadScene (
242
- jsonBackendMatch [ 1 ] ,
243
- jsonBackendMatch [ 2 ] ,
252
+ shareableLink [ 0 ] ,
253
+ shareableLink [ 1 ] ,
244
254
localDataState ,
245
255
) ;
246
256
}
247
257
scene . scrollToContent = true ;
248
258
if ( ! roomLinkData ) {
249
- window . history . replaceState ( { } , APP_NAME , window . location . origin ) ;
259
+ // window.history.replaceState({}, APP_NAME, window.location.origin);
250
260
}
251
261
} else {
252
262
// https://github.com/excalidraw/excalidraw/issues/1919
@@ -263,7 +273,7 @@ const initializeScene = async (opts: {
263
273
}
264
274
265
275
roomLinkData = null ;
266
- window . history . replaceState ( { } , APP_NAME , window . location . origin ) ;
276
+ // window.history.replaceState({}, APP_NAME, window.location.origin);
267
277
}
268
278
} else if ( externalUrlMatch ) {
269
279
window . history . replaceState ( { } , APP_NAME , window . location . origin ) ;
@@ -324,12 +334,12 @@ const initializeScene = async (opts: {
324
334
key : roomLinkData . roomKey ,
325
335
} ;
326
336
} else if ( scene ) {
327
- return isExternalScene && jsonBackendMatch
337
+ return isExternalScene && shareableLink
328
338
? {
329
339
scene,
330
340
isExternalScene,
331
- id : jsonBackendMatch [ 1 ] ,
332
- key : jsonBackendMatch [ 2 ] ,
341
+ id : shareableLink [ 0 ] ,
342
+ key : shareableLink [ 1 ] ,
333
343
}
334
344
: { scene, isExternalScene : false } ;
335
345
}
0 commit comments