File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
packages-exp/performance-exp/src Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,16 @@ export function initializePerformance(
79
79
// throw if an instance was already created.
80
80
// It could happen if initializePerformance() is called more than once, or getPerformance() is called first.
81
81
if ( provider . isInitialized ( ) ) {
82
- throw ERROR_FACTORY . create ( ErrorCode . ALREADY_INITIALIZED ) ;
82
+ const existingInstance = provider . getImmediate ( ) ;
83
+ const initialSettings = provider . getOptions ( ) as PerformanceSettings ;
84
+ if (
85
+ settings ?. dataCollectionEnabled === initialSettings ?. dataCollectionEnabled &&
86
+ settings ?. instrumentationEnabled === initialSettings ?. instrumentationEnabled
87
+ ) {
88
+ return existingInstance ;
89
+ } else {
90
+ throw ERROR_FACTORY . create ( ErrorCode . ALREADY_INITIALIZED ) ;
91
+ }
83
92
}
84
93
85
94
const perfInstance = provider . initialize ( {
Original file line number Diff line number Diff line change @@ -60,7 +60,11 @@ const ERROR_DESCRIPTION_MAP: { readonly [key in ErrorCode]: string } = {
60
60
'Custom metric name {$customMetricName} is invalid' ,
61
61
[ ErrorCode . INVALID_STRING_MERGER_PARAMETER ] :
62
62
'Input for String merger is invalid, contact support team to resolve.' ,
63
- [ ErrorCode . ALREADY_INITIALIZED ] : 'Performance can only be initialized once.'
63
+ [ ErrorCode . ALREADY_INITIALIZED ] :
64
+ 'initializePerformance() has already been called with ' +
65
+ 'different options. To avoid this error, call initializePerformance() with the ' +
66
+ 'same options as when it was originally called, or call getPerformance() to return the' +
67
+ ' already initialized instance.'
64
68
} ;
65
69
66
70
interface ErrorParams {
You can’t perform that action at this time.
0 commit comments