✨ Add url option to startView API#4199
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
7e83510 to
37f000a
Compare
|
I have read the CLA Document and I hereby sign the CLA |
Allow passing an explicit URL when calling startView() so frameworks like React Router v7 (framework mode) that update the URL after loaders complete can provide the correct destination URL upfront. Falls back to location.href when no url is provided.
37f000a to
4356546
Compare
|
@brettburley thanks for the contribution!. I'll take over the PR to add some tests and run the CI so we can merge it. |
|
🎯 Code Coverage (details) 🔗 Commit SHA: 9132945 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
…wUrl add undefined url test add test resource also gets the manual url
109262d to
7f6ff27
Compare
bcaudan
left a comment
There was a problem hiding this comment.
LGTM
A small note on public API doc
We should probably tweak it to:
- not misleading people to think that there is only name, service and version configurable
- not list every options available here
mormubis
left a comment
There was a problem hiding this comment.
No URL validation
The url field goes through unvalidated — if someone passes /dashboard instead of a full URL, view.url in the RUM event ends up as an origin-less string. The existing window.location.href path always gives a fully-qualified URL, so this quietly breaks in a way that didn't exist before.
Could normalize with new URL(url, location.href).href to handle relative URLs gracefully, or at least warn + fall back to location.href when the value isn't absolute.
Motivation
The
startView()API currently always captures the URL fromwindow.location.hrefat the moment it's called. This is a problem for frameworks like React Router v7 in framework mode (and similar async routing setups) where loaders/actions run before window.location is updated. This means the view gets recorded with the previous page's URL, leading to incorrect view data in RUM.Today,
ViewOptionsaccepts name, service, version, and context, but not url, so there is no way to customize this behavior without adding some non-trivial logic in thebeforeSendhook.Changes
Adds an optional
urlfield toViewOptionsso callers can explicitly provide the destination URL when the browser hasn't updatedwindow.locationyet. Falls back tolocation.hrefwhen not provided (no behavior change for existing users).Usage:
Test instructions
Checklist