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