@remix-run/router 1.0.5-pre.0 → 1.0.5-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/router.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.0.5-pre.0
2
+ * @remix-run/router v1.0.5-pre.1
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -2145,21 +2145,27 @@ function createRouter(init) {
2145
2145
 
2146
2146
 
2147
2147
  async function startRedirectNavigation(state, redirect, replace) {
2148
+ var _window;
2149
+
2148
2150
  if (redirect.revalidate) {
2149
2151
  isRevalidationRequired = true;
2150
2152
  }
2151
2153
 
2152
2154
  let redirectLocation = createLocation(state.location, redirect.location);
2153
- invariant(redirectLocation, "Expected a location on the redirect navigation");
2155
+ invariant(redirectLocation, "Expected a location on the redirect navigation"); // Check if this an external redirect that goes to a new origin
2154
2156
 
2155
- if (redirect.external && typeof window !== "undefined" && typeof window.location !== "undefined") {
2156
- if (replace) {
2157
- window.location.replace(redirect.location);
2158
- } else {
2159
- window.location.assign(redirect.location);
2160
- }
2157
+ if (typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {
2158
+ let newOrigin = createClientSideURL(redirect.location).origin;
2161
2159
 
2162
- return;
2160
+ if (window.location.origin !== newOrigin) {
2161
+ if (replace) {
2162
+ window.location.replace(redirect.location);
2163
+ } else {
2164
+ window.location.assign(redirect.location);
2165
+ }
2166
+
2167
+ return;
2168
+ }
2163
2169
  } // There's no need to abort on redirects, since we don't detect the
2164
2170
  // redirect until the action/loaders have settled
2165
2171
 
@@ -2490,7 +2496,7 @@ function unstable_createStaticHandler(routes, opts) {
2490
2496
 
2491
2497
  let result = await queryImpl(request, location, matches);
2492
2498
 
2493
- if (result instanceof Response) {
2499
+ if (isResponse(result)) {
2494
2500
  return result;
2495
2501
  } // When returning StaticHandlerContext, we patch back in the location here
2496
2502
  // since we need it for React Context. But this helps keep our submit and
@@ -2556,7 +2562,7 @@ function unstable_createStaticHandler(routes, opts) {
2556
2562
 
2557
2563
  let result = await queryImpl(request, location, matches, match);
2558
2564
 
2559
- if (result instanceof Response) {
2565
+ if (isResponse(result)) {
2560
2566
  return result;
2561
2567
  }
2562
2568
 
@@ -2585,7 +2591,7 @@ function unstable_createStaticHandler(routes, opts) {
2585
2591
  }
2586
2592
 
2587
2593
  let result = await loadRouteData(request, matches, routeMatch);
2588
- return result instanceof Response ? result : _extends({}, result, {
2594
+ return isResponse(result) ? result : _extends({}, result, {
2589
2595
  actionData: null,
2590
2596
  actionHeaders: {}
2591
2597
  });
@@ -2983,22 +2989,18 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
2983
2989
  request.signal.removeEventListener("abort", onReject);
2984
2990
  }
2985
2991
 
2986
- if (result instanceof Response) {
2992
+ if (isResponse(result)) {
2987
2993
  let status = result.status; // Process redirects
2988
2994
 
2989
2995
  if (redirectStatusCodes.has(status)) {
2990
2996
  let location = result.headers.get("Location");
2991
- invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header"); // Check if this an external redirect that goes to a new origin
2992
-
2993
- let currentUrl = new URL(request.url);
2994
- let currentOrigin = currentUrl.origin;
2995
- let newOrigin = new URL(location, currentOrigin).origin;
2996
- let external = newOrigin !== currentOrigin; // Support relative routing in internal redirects
2997
+ invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
2998
+ let isAbsolute = /^[a-z+]+:\/\//i.test(location) || location.startsWith("//"); // Support relative routing in internal redirects
2997
2999
 
2998
- if (!external) {
3000
+ if (!isAbsolute) {
2999
3001
  let activeMatches = matches.slice(0, matches.indexOf(match) + 1);
3000
3002
  let routePathnames = getPathContributingMatches(activeMatches).map(match => match.pathnameBase);
3001
- let resolvedLocation = resolveTo(location, routePathnames, currentUrl.pathname);
3003
+ let resolvedLocation = resolveTo(location, routePathnames, new URL(request.url).pathname);
3002
3004
  invariant(createPath(resolvedLocation), "Unable to resolve redirect location: " + location); // Prepend the basename to the redirect location if we have one
3003
3005
 
3004
3006
  if (basename) {
@@ -3022,8 +3024,7 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
3022
3024
  type: ResultType.redirect,
3023
3025
  status,
3024
3026
  location,
3025
- revalidate: result.headers.get("X-Remix-Revalidate") !== null,
3026
- external
3027
+ revalidate: result.headers.get("X-Remix-Revalidate") !== null
3027
3028
  };
3028
3029
  } // For SSR single-route requests, we want to hand Responses back directly
3029
3030
  // without unwrapping. We do this with the QueryRouteResponse wrapper
@@ -3341,8 +3342,12 @@ function isRedirectResult(result) {
3341
3342
  return (result && result.type) === ResultType.redirect;
3342
3343
  }
3343
3344
 
3345
+ function isResponse(value) {
3346
+ return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
3347
+ }
3348
+
3344
3349
  function isRedirectResponse(result) {
3345
- if (!(result instanceof Response)) {
3350
+ if (!isResponse(result)) {
3346
3351
  return false;
3347
3352
  }
3348
3353
 
@@ -3352,7 +3357,7 @@ function isRedirectResponse(result) {
3352
3357
  }
3353
3358
 
3354
3359
  function isQueryRouteResponse(obj) {
3355
- return obj && obj.response instanceof Response && (obj.type === ResultType.data || ResultType.error);
3360
+ return obj && isResponse(obj.response) && (obj.type === ResultType.data || ResultType.error);
3356
3361
  }
3357
3362
 
3358
3363
  function isValidMethod(method) {