@@ -148,6 +148,14 @@ function extractAndLoadSourceMapJSON(
148148 // Deduplicate fetches, since there can be multiple location keys per source map.
149149 const dedupedFetchPromises = new Map ( ) ;
150150
151+ if ( __DEBUG__ ) {
152+ console . log (
153+ 'extractAndLoadSourceMapJSON() load' ,
154+ locationKeyToHookSourceAndMetadata . size ,
155+ 'source maps' ,
156+ ) ;
157+ }
158+
151159 const setterPromises = [ ] ;
152160 locationKeyToHookSourceAndMetadata . forEach ( hookSourceAndMetadata => {
153161 const sourceMapRegex = / ? s o u r c e M a p p i n g U R L = ( [ ^ \s ' " ] + ) / gm;
@@ -177,45 +185,52 @@ function extractAndLoadSourceMapJSON(
177185 const sourceMappingURL = sourceMappingURLMatch [ 1 ] ;
178186 const hasInlineSourceMap = sourceMappingURL . indexOf ( 'base64,' ) >= 0 ;
179187 if ( hasInlineSourceMap ) {
180- // TODO (named hooks) deduplicate parsing in this branch (similar to fetching in the other branch)
181- // since there can be multiple location keys per source map.
182-
183- // Web apps like Code Sandbox embed multiple inline source maps.
184- // In this case, we need to loop through and find the right one.
185- // We may also need to trim any part of this string that isn't based64 encoded data.
186- const trimmed = ( ( sourceMappingURL . match (
187- / b a s e 6 4 , ( [ a - z A - Z 0 - 9 + \/ = ] + ) / ,
188- ) : any ) : Array < string > ) [ 1 ] ;
189- const decoded = withSyncPerformanceMark ( 'decodeBase64String()' , ( ) =>
190- decodeBase64String ( trimmed ) ,
191- ) ;
192-
193- const sourceMapJSON = withSyncPerformanceMark (
194- 'JSON.parse(decoded)' ,
195- ( ) => JSON . parse ( decoded ) ,
196- ) ;
188+ try {
189+ // TODO (named hooks) deduplicate parsing in this branch (similar to fetching in the other branch)
190+ // since there can be multiple location keys per source map.
191+
192+ // Web apps like Code Sandbox embed multiple inline source maps.
193+ // In this case, we need to loop through and find the right one.
194+ // We may also need to trim any part of this string that isn't based64 encoded data.
195+ const trimmed = ( ( sourceMappingURL . match (
196+ / b a s e 6 4 , ( [ a - z A - Z 0 - 9 + \/ = ] + ) / ,
197+ ) : any ) : Array < string > ) [ 1 ] ;
198+ const decoded = withSyncPerformanceMark (
199+ 'decodeBase64String()' ,
200+ ( ) => decodeBase64String ( trimmed ) ,
201+ ) ;
197202
198- if ( __DEBUG__ ) {
199- console . groupCollapsed (
200- 'extractAndLoadSourceMapJSON () Inline source map' ,
203+ const sourceMapJSON = withSyncPerformanceMark (
204+ 'JSON.parse(decoded)' ,
205+ ( ) => JSON . parse ( decoded ) ,
201206 ) ;
202- console . log ( sourceMapJSON ) ;
203- console . groupEnd ( ) ;
204- }
205207
206- // Hook source might be a URL like "https://4syus.csb.app/src/App.js"
207- // Parsed source map might be a partial path like "src/App.js"
208- if ( sourceMapIncludesSource ( sourceMapJSON , runtimeSourceURL ) ) {
209- hookSourceAndMetadata . sourceMapJSON = sourceMapJSON ;
208+ if ( __DEBUG__ ) {
209+ console . groupCollapsed (
210+ 'extractAndLoadSourceMapJSON() Inline source map' ,
211+ ) ;
212+ console . log ( sourceMapJSON ) ;
213+ console . groupEnd ( ) ;
214+ }
215+
216+ // Hook source might be a URL like "https://4syus.csb.app/src/App.js"
217+ // Parsed source map might be a partial path like "src/App.js"
218+ if ( sourceMapIncludesSource ( sourceMapJSON , runtimeSourceURL ) ) {
219+ hookSourceAndMetadata . sourceMapJSON = sourceMapJSON ;
210220
211- // OPTIMIZATION If we've located a source map for this source,
212- // we'll use it to retrieve the original source (to extract hook names).
213- // We only fall back to parsing the full source code is when there's no source map.
214- // The source is (potentially) very large,
215- // So we can avoid the overhead of serializing it unnecessarily.
216- hookSourceAndMetadata . runtimeSourceCode = null ;
221+ // OPTIMIZATION If we've located a source map for this source,
222+ // we'll use it to retrieve the original source (to extract hook names).
223+ // We only fall back to parsing the full source code is when there's no source map.
224+ // The source is (potentially) very large,
225+ // So we can avoid the overhead of serializing it unnecessarily.
226+ hookSourceAndMetadata . runtimeSourceCode = null ;
217227
218- break ;
228+ break ;
229+ }
230+ } catch ( error ) {
231+ // We've likely encountered a string in the source code that looks like a source map but isn't.
232+ // Maybe the source code contains a "sourceMappingURL" comment or soething similar.
233+ // In either case, let's skip this and keep looking.
219234 }
220235 } else {
221236 externalSourceMapURLs . push ( sourceMappingURL ) ;
0 commit comments