Skip to content

Commit

Permalink
drop attribute that prevents cookies from being sent for asset request (
Browse files Browse the repository at this point in the history
#8520)

## Summary

As reported by Motion, 
```
<link href="https://pri.highlight.io/assets/1079/91f4wuyZMOLJLcHQvjepfJVKYQxx1Rrv7PWSq7RJjZ8~" rel="stylesheet">
```
loads correctly from our asset cache from app.highlight.io with the
assets cookie, while
```
<link href="https://pri.highlight.io/assets/1079/_ZQLI9RtgPGhqFe1X1WDaigth52_TOp9ZNUmEenxIxY~" rel="modulepreload">
<link crossorigin="" href="https://pri.highlight.io/assets/1079/l4NeTC0Z_WRgQW7I6x9qBA22t1B6oVZk6XZFjBDgpoY~" rel="modulepreload">
```
do not load because of the `rel="modulepreload"` attribute.

We should drop the `rel` attribute as it is a performance optimization
for page load that isn't required to play back the session.

## How did you test this change?

unit testing in parse_test.go

## Are there any deployment considerations?

monitoring motion deploy

## Does this work require review from our design team?

no
  • Loading branch information
Vadman97 committed May 10, 2024
1 parent 97ba0ca commit 296f846
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
3 changes: 3 additions & 0 deletions backend/event-parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,9 @@ func tryGetAssetUrls(ctx context.Context, projectId int, node map[string]interfa
newUrl, ok := replacements[href]
if ok {
attributes["href"] = newUrl
if rel, ok := attributes["rel"].(string); ok && rel == "modulepreload" {
delete(attributes, "rel")
}
}
urls = append(urls, href)
}
Expand Down
28 changes: 28 additions & 0 deletions backend/event-parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,34 @@ func TestSnapshot_ReplaceAssets(t *testing.T) {
}
assert.True(t, matched, "no asset matched %s", exp)
}

gotMsg, err := snapshot.Encode()
if err != nil {
t.Fatalf("error marshalling: %v", err)
}

var gotInterface struct {
Node struct {
ChildNodes []struct {
ChildNodes []struct {
ChildNodes []struct {
Id int `json:"id"`
Attributes map[string]interface{} `json:"attributes"`
} `json:"childNodes"`
} `json:"childNodes"`
} `json:"childNodes"`
} `json:"node"`
}
err = json.Unmarshal(gotMsg, &gotInterface)
if err != nil {
t.Fatalf("error getting interface: %v", err)
}

assert.Equal(t, gotInterface.Node.ChildNodes[1].ChildNodes[0].ChildNodes[30].Id, 36)
assert.Equal(t, gotInterface.Node.ChildNodes[1].ChildNodes[0].ChildNodes[31].Id, 37)

assert.Nil(t, gotInterface.Node.ChildNodes[1].ChildNodes[0].ChildNodes[30].Attributes["rel"])
assert.Nil(t, gotInterface.Node.ChildNodes[1].ChildNodes[0].ChildNodes[31].Attributes["rel"])
})
}
func TestSnapshot_ReplaceAssets_Capacitor(t *testing.T) {
Expand Down
16 changes: 11 additions & 5 deletions backend/event-parse/sample-events/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,24 @@
"type": 2
},
{
"attributes": {
"href": "https://pri.highlight.io/assets/1079/l4NeTC0Z_WRgQW7I6x9qBA22t1B6oVZk6XZFjBDgpoY~",
"rel": "modulepreload"
},
"childNodes": [],
"id": 36,
"textContent": "\n ",
"type": 3
"tagName": "link",
"type": 2
},
{
"attributes": {
"content": "Highlight gives your team full transparency into the errors, interactions, and performance metrics of your client-side application.",
"property": "og:description"
"href": "https://pri.highlight.io/assets/1079/_ZQLI9RtgPGhqFe1X1WDaigth52_TOp9ZNUmEenxIxY~",
"rel": "modulepreload",
"crossorigin": ""
},
"childNodes": [],
"id": 37,
"tagName": "meta",
"tagName": "link",
"type": 2
},
{
Expand Down
16 changes: 11 additions & 5 deletions backend/event-parse/sample-events/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,24 @@
"type": 2
},
{
"attributes": {
"href": "https://pri.highlight.io/assets/1079/l4NeTC0Z_WRgQW7I6x9qBA22t1B6oVZk6XZFjBDgpoY~",
"rel": "modulepreload"
},
"childNodes": [],
"id": 36,
"textContent": "\n ",
"type": 3
"tagName": "link",
"type": 2
},
{
"attributes": {
"content": "Highlight gives your team full transparency into the errors, interactions, and performance metrics of your client-side application.",
"property": "og:description"
"href": "https://pri.highlight.io/assets/1079/_ZQLI9RtgPGhqFe1X1WDaigth52_TOp9ZNUmEenxIxY~",
"rel": "modulepreload",
"crossorigin": ""
},
"childNodes": [],
"id": 37,
"tagName": "meta",
"tagName": "link",
"type": 2
},
{
Expand Down

0 comments on commit 296f846

Please sign in to comment.