-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(remix): Support merging json
responses from root loader functions.
#5548
Conversation
f3c0155
to
80d1711
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
}); | ||
} | ||
|
||
test('should inject `sentry-trace` and `baggage` into root loader returning `{}`.', async ({ page }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('should inject `sentry-trace` and `baggage` into root loader returning `{}`.', async ({ page }) => { | |
test('should inject `sentry-trace` and `baggage` into root loader returning an empty object.', async ({ page }) => { |
return redirect('/plain'); | ||
case 'return-redirect-json': | ||
return redirect('/json'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need a default
case here? Maybe log a warning if theres a type not defined here?
|
||
export function getRouteData(page: Page): Promise<any> { | ||
return page.evaluate('window.__remixContext.routeData').catch(err => { | ||
return {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log out the error?
const envelope = await getEnvelopeRequest(url); | ||
const transaction = envelope[2]; | ||
|
||
assertSentryTransaction(transaction, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we delete this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer have a case where there's no loader
in root.tsx
defined.
Might need to utilize multiple projects to be able to test those kind of conflicted scenarios. We will probably need a similar thing to test manual wrappers too.
Trying to figure out now, will add that to this PR, if it doesn't require a large structural change.
@AbhiPrasad I'm converting this to draft for now. :( Apart from the required test structure updates, it also seems the |
Can we still get the fix merged in to unblock users? We can always figure out the tests afterwards. |
Sure, also fixed the problem about redirect responses. |
const data = await extractData(res); | ||
|
||
if (typeof data === 'object') { | ||
return { ...data, ...traceAndBaggage }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to even return traceAndBaggage
if it's a response? Couldn't we just just return the res?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait I'm dumb - yes we do, nvm.
if (isResponse(res) && !isRedirectResponse(res) && !isCatchResponse(res)) { | ||
const data = await extractData(res); | ||
|
||
if (typeof data === 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AbhiPrasad, the else
case of this is a bit weird (when data is primitive). It doesn't sound right to return a primitive from a loader
, but TS definitions allow it.
So, would it make sense if we skip injection in such cases?
It may mess up the response when we spread it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I would rather we skip injection here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to figure out the loader not being defined case later (for the deleted test) - I'm comfortable shipping what we got for now!
Resolves #5539
Introduces support of
json
responses while injectingsentryTrace
andsentryBaggage
into theroot
loader.Added a set of tests to ensure that we don't omit user-defined loader responses.