Skip to content

Commit 890ed5b

Browse files
committed
direct match
1 parent 4e4d40a commit 890ed5b

3 files changed

Lines changed: 17 additions & 30 deletions

File tree

src/common/v2/script-tracker.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,12 @@ export const scriptCorrelations = new Map()
3030
let poSubscribers = []
3131

3232
/**
33-
* Checks if two URLs match using flexible suffix matching
34-
* @param {string} url1 - First URL
35-
* @param {string} url2 - Second URL
36-
* @returns {boolean} True if URLs match
37-
*/
38-
function urlsMatch (url1, url2) {
39-
return url1.endsWith(url2) || url2.endsWith(url1)
40-
}
41-
42-
/**
43-
* Retrieves a script correlation by URL, falling back to use flexible matching (suffix matching in both directions) if no exact match is found
33+
* Retrieves a script correlation by URL using exact matching
4434
* @param {string} targetUrl - The URL to find
4535
* @returns {ScriptCorrelation | undefined} - The correlation object if found
4636
*/
4737
function findCorrelation (targetUrl) {
48-
if (scriptCorrelations.has(targetUrl)) return scriptCorrelations.get(targetUrl)
49-
for (const [url, correlation] of scriptCorrelations) {
50-
if (urlsMatch(url, targetUrl)) return correlation
51-
}
38+
return scriptCorrelations.get(targetUrl)
5239
}
5340

5441
/**
@@ -187,14 +174,14 @@ function wasPreloaded (targetUrl) {
187174
}
188175

189176
/**
190-
* Checks if a performance entry matches the target MFE script URL
177+
* Checks if a performance entry matches the target MFE script URL using exact matching
191178
* @param {PerformanceResourceTiming} entry - The resource timing entry
192179
* @param {string} targetUrl - The MFE script URL to match
193180
* @returns {boolean} True if the entry matches
194181
*/
195182
function entryMatchesUrl (entry, targetUrl) {
196183
const entryUrl = cleanURL(entry.name)
197-
return urlsMatch(entryUrl, targetUrl)
184+
return entryUrl === targetUrl
198185
}
199186

200187
/**

tests/unit/common/util/script-tracker-correlations.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -953,9 +953,8 @@ describe('script-tracker correlations', () => {
953953
expect(correlations.length).toBe(2)
954954
})
955955

956-
test('URL matching handles partial URLs correctly', () => {
956+
test('URL matching requires exact match', () => {
957957
const fullUrl = 'https://cdn.example.com/path/to/mfe.js'
958-
const partialUrl = '/path/to/mfe.js'
959958

960959
const perfEntry = {
961960
name: fullUrl,
@@ -973,9 +972,10 @@ describe('script-tracker correlations', () => {
973972
}
974973

975974
mockNavigationEntry = { name: 'https://example.com/' }
975+
// Stack trace also has absolute URL (per spec)
976976
mockStack = `Error
977977
at findScriptTimings (${scriptTrackerModule.thisFile}:1:1)
978-
at init (${partialUrl}:10:5)`
978+
at init (${fullUrl}:10:5)`
979979

980980
// Make performance entry available for findScriptTimings lookup
981981
globalThis.performance.getEntriesByType = jest.fn((type) => {
@@ -987,7 +987,7 @@ describe('script-tracker correlations', () => {
987987
currentTime = 100
988988
const timings = scriptTrackerModule.findScriptTimings()
989989

990-
// Should match even with partial URL
990+
// Should match with exact URL
991991
expect(timings.asset).toBe(fullUrl)
992992
expect(timings.fetchStart).toBe(10)
993993
expect(timings.fetchEnd).toBe(40)

tests/unit/common/util/script-tracker.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ describe('script-tracker', () => {
421421
expect(result.fetchEnd).toBe(0)
422422
})
423423

424-
test('handles URL matching when entry URL ends with stack URL', () => {
425-
// Resource entry has full path
424+
test('handles URL matching with exact match', () => {
425+
// Resource entry has absolute URL
426426
const mockResourceEntry = {
427427
name: 'https://cdn.example.com/path/app.js',
428428
initiatorType: 'script',
@@ -439,23 +439,23 @@ describe('script-tracker', () => {
439439
return []
440440
})
441441

442-
// Stack contains full URL matching the resource entry
442+
// Stack contains full URL matching the resource entry exactly
443443
mockStack = `Error
444444
at findScriptTimings (${scriptTrackerModule.thisFile}:1:1)
445445
at register (${scriptTrackerModule.thisFile}:2:2)
446446
at func (https://cdn.example.com/path/app.js:5:10)`
447447

448448
const result = scriptTrackerModule.findScriptTimings()
449449

450-
// URL matching succeeds, timing info retrieved
450+
// Exact URL matching succeeds, timing info retrieved
451451
expect(result.fetchStart).toBe(100)
452452
expect(result.type).toBe('script')
453453
})
454454

455-
test('handles URL matching when stack URL ends with entry URL', () => {
456-
// Resource entry has short relative name
455+
test('handles URL matching with absolute URLs', () => {
456+
// Resource entry has absolute URL (per spec)
457457
const mockResourceEntry = {
458-
name: 'app.js',
458+
name: 'https://cdn.example.com/path/app.js',
459459
initiatorType: 'script',
460460
startTime: 100,
461461
responseEnd: 200
@@ -470,13 +470,13 @@ describe('script-tracker', () => {
470470
return []
471471
})
472472

473-
// Stack has full URL that ends with entry name
473+
// Stack has same absolute URL
474474
mockStack = `Error
475475
at func (https://cdn.example.com/path/app.js:5:10)`
476476

477477
const result = scriptTrackerModule.findScriptTimings()
478478

479-
// Reverse matching: stack URL ends with entry URL
479+
// Exact URL matching
480480
expect(result.fetchStart).toBe(100)
481481
expect(result.type).toBe('script')
482482
})

0 commit comments

Comments
 (0)