Conversation
| ? `renderError: (ctx) => { | ||
| return React.createElement(Error, { | ||
| url: ctx.request.URL, | ||
| url: ctx.request.url, |
There was a problem hiding this comment.
dont think this does anything really
|
|
||
| const locationString = | ||
| typeof location === 'object' ? location.href : location; | ||
| typeof location === 'object' ? location.pathname : location; |
There was a problem hiding this comment.
whyyy, like whyyyy
There was a problem hiding this comment.
In react router's doc. You are suppose to use req.url
The example for the url being In the request www.example.com/index.html?a=1&b=2, req.url will contain /index.html?a=1&b=2. which does not explain why pathname works
|
so to summarize what I found so far passing in object to StaticRouter This is currently what web uses with react-router-dom@5.1.2 passing in location.href (ie. https://site-name.com/test123) to StaticRouter This is currently what beta buddy uses with react-router-dom@5.2.0 *passin in location.pathname (ie. /test123) to StaticRouter* |
|
@gmcgibbon did a little digging into react-router for me So it looks like we do have to use either an URL object or a path string |
Logging this here I see: The path name gets reset to |
We paired on this, and that is indeed the case. We tracked it down to https://github.com/ReactTraining/history/blob/v4.10.1/modules/LocationUtils.js#L6. Since this is an outdated version of the history package, the latest version doesn't include this function, and fixing this might take some time to get released, we can instead sidestep this by simply passing in the pathname as a string. |
|
What an amazing find by @gmcgibbon !!! 👏 👏 👏 To recap: This also explains why web & beta buddy is working ok since they are both using history@4.9.0 |
|
I think what make the most sense right now would be
|
2741235 to
bed9e55
Compare
2e12655 to
6d1054a
Compare
| typeof location === 'object' | ||
| ? { | ||
| pathname: location.pathname, | ||
| search: location.search, | ||
| hash: '', | ||
| state: undefined, | ||
| } |
There was a problem hiding this comment.
🛑 Final thought:
The reason why this have to happen is this line
location = { ...path }
where history is using spread operator to copy the object before using it, and we pass in URL object and copying it using spread operator means we lost all the property we actually do care about (like pathname & search).
Since the document recommend using { pathname, search, hash, state } instead of URL object.
I am updating the type to reflect the only two pieces of information we need, and building an object to pass into StaticRouter that reflect this.
This example below illustrate what it looks like using spread operator on URL object
> const url = new URL('https://gestalt-web-application-example.myshopify.io/test123');
undefined
> url
URL {
href:
'https://gestalt-web-application-example.myshopify.io/test123',
origin: 'https://gestalt-web-application-example.myshopify.io',
protocol: 'https:',
username: '',
password: '',
host: 'gestalt-web-application-example.myshopify.io',
hostname: 'gestalt-web-application-example.myshopify.io',
port: '',
pathname: '/test123',
search: '',
searchParams: URLSearchParams {},
hash: '' }
> const foo = {...url};
undefined
> foo
{ [Symbol(context)]:
URLContext {
flags: 400,
scheme: 'https:',
username: '',
password: '',
host: 'gestalt-web-application-example.myshopify.io',
port: null,
path: [ 'test123' ],
query: null,
fragment: null },
[Symbol(query)]: URLSearchParams {} }
>
marutypes
left a comment
There was a problem hiding this comment.
Makes sense, this bug is super non-obvious so I'm glad we have a comment in the code :)
Description
Fixes (issue #)
Related #1581, #1567
Type of change
Checklist