@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.
@@ -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
  *
@@ -2195,21 +2195,27 @@
2195
2195
 
2196
2196
 
2197
2197
  async function startRedirectNavigation(state, redirect, replace) {
2198
+ var _window;
2199
+
2198
2200
  if (redirect.revalidate) {
2199
2201
  isRevalidationRequired = true;
2200
2202
  }
2201
2203
 
2202
2204
  let redirectLocation = createLocation(state.location, redirect.location);
2203
- invariant(redirectLocation, "Expected a location on the redirect navigation");
2205
+ invariant(redirectLocation, "Expected a location on the redirect navigation"); // Check if this an external redirect that goes to a new origin
2204
2206
 
2205
- if (redirect.external && typeof window !== "undefined" && typeof window.location !== "undefined") {
2206
- if (replace) {
2207
- window.location.replace(redirect.location);
2208
- } else {
2209
- window.location.assign(redirect.location);
2210
- }
2207
+ if (typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {
2208
+ let newOrigin = createClientSideURL(redirect.location).origin;
2211
2209
 
2212
- return;
2210
+ if (window.location.origin !== newOrigin) {
2211
+ if (replace) {
2212
+ window.location.replace(redirect.location);
2213
+ } else {
2214
+ window.location.assign(redirect.location);
2215
+ }
2216
+
2217
+ return;
2218
+ }
2213
2219
  } // There's no need to abort on redirects, since we don't detect the
2214
2220
  // redirect until the action/loaders have settled
2215
2221
 
@@ -2540,7 +2546,7 @@
2540
2546
 
2541
2547
  let result = await queryImpl(request, location, matches);
2542
2548
 
2543
- if (result instanceof Response) {
2549
+ if (isResponse(result)) {
2544
2550
  return result;
2545
2551
  } // When returning StaticHandlerContext, we patch back in the location here
2546
2552
  // since we need it for React Context. But this helps keep our submit and
@@ -2606,7 +2612,7 @@
2606
2612
 
2607
2613
  let result = await queryImpl(request, location, matches, match);
2608
2614
 
2609
- if (result instanceof Response) {
2615
+ if (isResponse(result)) {
2610
2616
  return result;
2611
2617
  }
2612
2618
 
@@ -2635,7 +2641,7 @@
2635
2641
  }
2636
2642
 
2637
2643
  let result = await loadRouteData(request, matches, routeMatch);
2638
- return result instanceof Response ? result : _extends({}, result, {
2644
+ return isResponse(result) ? result : _extends({}, result, {
2639
2645
  actionData: null,
2640
2646
  actionHeaders: {}
2641
2647
  });
@@ -3033,22 +3039,18 @@
3033
3039
  request.signal.removeEventListener("abort", onReject);
3034
3040
  }
3035
3041
 
3036
- if (result instanceof Response) {
3042
+ if (isResponse(result)) {
3037
3043
  let status = result.status; // Process redirects
3038
3044
 
3039
3045
  if (redirectStatusCodes.has(status)) {
3040
3046
  let location = result.headers.get("Location");
3041
- 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
3042
-
3043
- let currentUrl = new URL(request.url);
3044
- let currentOrigin = currentUrl.origin;
3045
- let newOrigin = new URL(location, currentOrigin).origin;
3046
- let external = newOrigin !== currentOrigin; // Support relative routing in internal redirects
3047
+ invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
3048
+ let isAbsolute = /^[a-z+]+:\/\//i.test(location) || location.startsWith("//"); // Support relative routing in internal redirects
3047
3049
 
3048
- if (!external) {
3050
+ if (!isAbsolute) {
3049
3051
  let activeMatches = matches.slice(0, matches.indexOf(match) + 1);
3050
3052
  let routePathnames = getPathContributingMatches(activeMatches).map(match => match.pathnameBase);
3051
- let resolvedLocation = resolveTo(location, routePathnames, currentUrl.pathname);
3053
+ let resolvedLocation = resolveTo(location, routePathnames, new URL(request.url).pathname);
3052
3054
  invariant(createPath(resolvedLocation), "Unable to resolve redirect location: " + location); // Prepend the basename to the redirect location if we have one
3053
3055
 
3054
3056
  if (basename) {
@@ -3072,8 +3074,7 @@
3072
3074
  type: ResultType.redirect,
3073
3075
  status,
3074
3076
  location,
3075
- revalidate: result.headers.get("X-Remix-Revalidate") !== null,
3076
- external
3077
+ revalidate: result.headers.get("X-Remix-Revalidate") !== null
3077
3078
  };
3078
3079
  } // For SSR single-route requests, we want to hand Responses back directly
3079
3080
  // without unwrapping. We do this with the QueryRouteResponse wrapper
@@ -3391,8 +3392,12 @@
3391
3392
  return (result && result.type) === ResultType.redirect;
3392
3393
  }
3393
3394
 
3395
+ function isResponse(value) {
3396
+ return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
3397
+ }
3398
+
3394
3399
  function isRedirectResponse(result) {
3395
- if (!(result instanceof Response)) {
3400
+ if (!isResponse(result)) {
3396
3401
  return false;
3397
3402
  }
3398
3403
 
@@ -3402,7 +3407,7 @@
3402
3407
  }
3403
3408
 
3404
3409
  function isQueryRouteResponse(obj) {
3405
- return obj && obj.response instanceof Response && (obj.type === ResultType.data || ResultType.error);
3410
+ return obj && isResponse(obj.response) && (obj.type === ResultType.data || ResultType.error);
3406
3411
  }
3407
3412
 
3408
3413
  function isValidMethod(method) {