Closed jsnajdr closed 3 days ago
https://calypso.live?image=registry.a8c.com/calypso/app:build-125051&env=jetpack |
https://calypso.live?image=registry.a8c.com/calypso/app:build-125051&env=a8c-for-agencies |
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:
App Entrypoints (~17 bytes added 📈 [gzipped])
Legend
Generated by performance advisor bot at iscalypsofastyet.com.
This PR modifies the release build for the following Calypso Apps:
For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run install-plugin.sh $pluginSlug fix/router-double-leading-slash
on your sandbox.
Fixes a bug where link in Calypso UI like:
is incorrectly interpreted by the Calypso router and causes navigation to
https://jetpack.com
.The Calypso router has a
clickHandler
that captures all clicks ona href
elements and tries to do an SPA navigation. Thepathname
of the offending URL is//jetpack.com
, and because no matching route is registered in Calypso for this path, eventually the router does a full-page navigation by assigning towindow.location.href
:But here the path is not interpreted as a relative
pathname
, but as a scheme-relative URL tojetpack.com
.This is a counterintutitive behavior of URLs because when parsing and composing an URL with the native
URL
class is not "symmetrical":produces a parsed object with
{ host: 'wordpress.com', pathname: '//jetpack.com' }
. But trying to use the pathname as a relative URL leads to something different:produces a parsed object with
{ host: 'jetpack.com' }
. Only thehttps
scheme is used from the base URL.I'm fixing this by removing extra leading slashes from the
path
when producing a routerContext
object. This way the offending path is never assigned towindow.location
and is also never passed towindow.history.pushState
.How to test: Put a
<a href>
element somewhere in Calypso React UI and click on it. Unpatched Calypso will navigate tohttp://jetpack.com
. Patched Calypso will navigate to local/jetpack.com
.