@remix-run/router 0.2.0-pre.8 → 1.0.0

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,159 +1,14 @@
1
1
  # @remix-run/router
2
2
 
3
- ## 0.2.0-pre.8
3
+ ## 1.0.0
4
4
 
5
- ### Patch Changes
5
+ This is the first stable release of `@remix-run/router`, which provides all the underlying routing and data loading/mutation logic for `react-router`. You should _not_ be using this package directly unless you are authoring a routing library similar to `react-router`.
6
6
 
7
- - fix: avoid uneccesary re-renders on `defer` resolution (#9155)
8
- - fix: pass `useMatches` objects to `ScrollRestoration` `getKey` (#9157)
9
- - fix: fetcher submission revalidating fetchers using wrong key (#9166)
10
- - fix: use a push navigation on submission errors (#9162)
7
+ For an overview of the features provided by `react-router`, we recommend you go check out the [docs][rr-docs], especially the [feature overview][rr-feature-overview] and the [tutorial][rr-tutorial].
11
8
 
12
- ## 0.2.0-pre.7
9
+ For an overview of the features provided by `@remix-run/router`, please check out the [README][remix-router-readme].
13
10
 
14
- ### Patch Changes
15
-
16
- - fix: fix default redirect push/replace behavior (#9117)
17
-
18
- ## 0.2.0-pre.6
19
-
20
- ### Patch Changes
21
-
22
- - fix: Rename `<Deferred>` to `<Await>` (#9095)
23
-
24
- - We are no longer replacing the `Promise` on `loaderData` with the value/error
25
- when it settles so it's now always a `Promise`.
26
- - To that end, we changed from `<Deferred value={promise}>` to
27
- `<Await resolve={promise}>` for clarity, and it also now supports using
28
- `<Await>` with raw promises from anywhere, not only those on `loaderData`
29
- from a defer() call.
30
- - Note that raw promises will not be automatically cancelled on interruptions
31
- so they are not recommended
32
- - The hooks are now `useAsyncValue`/`useAsyncError`
33
-
34
- ## 0.2.0-pre.5
35
-
36
- ### Patch Changes
37
-
38
- - feat: Deferred API Updates (#9070)
39
-
40
- - Support array and single promise usages
41
- - `return defer([ await critical(), lazy() ])`
42
- - `return defer(lazy())`
43
- - Remove `Deferrable`/`ResolvedDeferrable` in favor of raw `Promise`'s and `Awaited`
44
- - Remove generics from `useAsyncValue` until `useLoaderData` generic is decided in 6.5
45
-
46
- - feat: Add `createStaticRouter` for `@remix-run/router` SSR usage (#9013)
47
-
48
- **Notable changes:**
49
-
50
- - `request` is now the driving force inside the router utils, so that we can better handle `Request` instances coming form the server (as opposed to `string` and `Path` instances coming from the client)
51
- - Removed the `signal` param from `loader` and `action` functions in favor of `request.signal`
52
-
53
- **Example usage (Document Requests):**
54
-
55
- ```jsx
56
- // Create a static handler
57
- let { query } = unstable_createStaticHandler(routes);
58
-
59
- // Perform a full-document query for the incoming Fetch Request. This will
60
- // execute the appropriate action/loaders and return either the state or a
61
- // Fetch Response in the case of redirects.
62
- let state = await query(fetchRequest);
63
-
64
- // If we received a Fetch Response back, let our server runtime handle directly
65
- if (state instanceof Response) {
66
- throw state;
67
- }
68
-
69
- // Otherwise, render our application providing the data routes and state
70
- let html = ReactDOMServer.renderToString(
71
- <React.StrictMode>
72
- <DataStaticRouter routes={routes} state={state} />
73
- </React.StrictMode>
74
- );
75
- ```
76
-
77
- **Example usage (Data Requests):**
78
-
79
- ```jsx
80
- // Create a static route handler
81
- let { queryRoute } = unstable_createStaticHandler(routes);
82
-
83
- // Perform a single-route query for the incoming Fetch Request. This will
84
- // execute the appropriate singular action/loader and return either the raw
85
- // data or a Fetch Response
86
- let data = await queryRoute(fetchRequest);
87
-
88
- // If we received a Fetch Response back, return it directly
89
- if (data instanceof Response) {
90
- return data;
91
- }
92
-
93
- // Otherwise, construct a Response from the raw data (assuming json here)
94
- return new Response(JSON.stringify(data), {
95
- headers: {
96
- "Content-Type": "application/json; charset=utf-8",
97
- },
98
- });
99
- ```
100
-
101
- - feat: SSR Updates for React Router (#9058)
102
-
103
- _Note: The Data-Router SSR aspects of `@remix-run/router` and `react-router-dom` are being released as **unstable** in this release (`unstable_createStaticHandler` and `unstable_DataStaticRouter`), and we plan to finalize them in a subsequent minor release once the kinks can be worked out with the Remix integration. To that end, they are available for use, but are subject to breaking changes in the next minor release._
104
-
105
- - Remove `useRenderDataRouter()` in favor of `<DataRouterProvider>`/`<DataRouter>`
106
- - Support automatic hydration in `<DataStaticRouter>`/`<DataBrowserRouter>`/`<DataHashRouter>`
107
- - Uses `window.__staticRouterHydrationData`
108
- - Can be disabled on the server via `<DataStaticRouter hydrate={false}>`
109
- - Can be disabled (or overridden) in the browser by passing `hydrationData` to `<DataBrowserRouter>`/`<DataHashRouter>`
110
- - `<DataStaticRouter>` now tracks it's own SSR error boundaries on `StaticHandlerContext`
111
- - `StaticHandlerContext` now exposes `statusCode`/`loaderHeaders`/`actionHeaders`
112
- - `foundMissingHydrationData` check removed since Remix routes may have loaders (for modules) that don't return data for `loaderData`
113
-
114
- ## 0.2.0-pre.4
115
-
116
- ### Patch Changes
117
-
118
- - fix: Handle fetcher 404s as normal boundary errors (#9015)
119
- - feat: adds `defer()` support to data routers (#9002)
120
- - feat: add basename support for data routers (#9026)
121
- - ci: simplify dist/ directory for CJS/ESM only (#9017)
122
- - fix: Fix trailing slash behavior on pathless routing when using a basename (#9045)
123
-
124
- ## 0.2.0-pre.3
125
-
126
- ### Patch Changes
127
-
128
- - fix: properly handle `<Form encType="multipart/form-data">` submissions (#8984)
129
- - fix: Make path resolution trailing slash agnostic (#8861)
130
- - fix: don't default to a `REPLACE` navigation on form submissions if the action redirected. The redirect takes care of avoiding the back-button-resubmit scenario, so by using a `PUSH` we allow the back button to go back to the pre-submission form page (#8979)
131
- - fix: export ActionFunctionArgs/LoaderFunctionArgs up through router packages (#8975)
132
- - fix: preserve loader data for loaders that opted out of revalidation (#8973)
133
-
134
- [Full Changes](https://github.com/remix-run/react-router/compare/%40remix-run/router%400.2.0-pre.2...%40remix-run/router%400.2.0-pre.3)
135
-
136
- ## 0.2.0-pre.2
137
-
138
- ### Patch Changes
139
-
140
- - Capture fetcher errors at contextual route error boundaries (#8945)
141
-
142
- ## 0.2.0-pre.1
143
-
144
- ### Patch Changes
145
-
146
- - Fix missing `dist` files
147
-
148
- ## 0.2.0-pre.0
149
-
150
- ### Minor Changes
151
-
152
- - Change `formMethod=GET` to be a loading navigation instead of submitting
153
-
154
- ### Patch Changes
155
-
156
- - Make `fallbackElement` optional and change type to `ReactNode` (type changes only) (#8896)
157
- - Properly trigger error boundaries on 404 routes
158
- - Fix `resolveTo` so that it does not mutate the provided pathname (#8839)
159
- - Pass fetcher `actionResult` through to `shouldRevalidate` on fetcher submissions
11
+ [rr-docs]: https://reactrouter.com/
12
+ [rr-feature-overview]: https://reactrouter.com/en/v6.4.0/start/overview
13
+ [rr-tutorial]: https://reactrouter.com/en/v6.4.0/start/tutorial
14
+ [remix-router-readme]: https://github.com/remix-run/react-router/blob/main/packages/router/README.md
package/README.md CHANGED
@@ -1,11 +1,12 @@
1
- # Router
1
+ # Remix Router
2
2
 
3
- The `@remix-run/router` package is the heart of [React Router](https://github.com/remix-run/react-router) and provides all the core functionality for routing, data loading, data mutations, and navigation.
3
+ The `@remix-run/router` package is a framework-agnostic routing package (sometimes referred to as a browser-emulator) that serves as the heart of [React Router][react-router] and [Remix][remix] and provides all the core functionality for routing coupled with data loading and data mutations. It comes with built-in handling of errors, race-conditions, interruptions, cancellations, lazy-loading data, and much, much more.
4
4
 
5
- If you're using React Router, you should never `import` anything directly from
6
- the `@remix-run/router` or `react-router` packages, but you should have everything
7
- you need in either `react-router-dom` or `react-router-native`. Both of those
8
- packages re-export everything from `@remix-run/router` and `react-router`.
5
+ If you're using React Router, you should never `import` anything directly from the `@remix-run/router` or `react-router` packages, but you should have everything you need in either `react-router-dom` or `react-router-native`. Both of those packages re-export everything from `@remix-run/router` and `react-router`.
6
+
7
+ > **Warning**
8
+ >
9
+ > This router is a low-level package intended to be consumed by UI layer routing libraries. You should very likely not be using this package directly unless you are authoring a routing library such as [`react-router-dom`][react-router-repo] or one of it's other [UI ports][remix-routers-repo].
9
10
 
10
11
  ## API
11
12
 
@@ -15,12 +16,10 @@ A Router instance can be created using `createRouter`:
15
16
  // Create and initialize a router. "initialize" contains all side effects
16
17
  // including history listeners and kicking off the initial data fetch
17
18
  let router = createRouter({
18
- // Routes array using react-router RouteObject's
19
- routes,
19
+ // Routes array
20
+ routes: ,
20
21
  // History instance
21
22
  history,
22
- // Optional hydration data for SSR apps
23
- hydrationData?: HydrationState;
24
23
  }).initialize()
25
24
  ```
26
25
 
@@ -28,6 +27,8 @@ Internally, the Router represents the state in an object of the following format
28
27
 
29
28
  ```ts
30
29
  interface RouterState {
30
+ // False during the initial data load, true once we have our initial data
31
+ initialized: boolean;
31
32
  // The `history` action of the most recently completed navigation
32
33
  historyAction: Action;
33
34
  // The current location of the router. During a navigation this reflects
@@ -35,18 +36,10 @@ interface RouterState {
35
36
  location: Location;
36
37
  // The current set of route matches
37
38
  matches: DataRouteMatch[];
38
- // False during the initial data load, true once we have our initial data
39
- initialized: boolean;
40
39
  // The state of the current navigation
41
40
  navigation: Navigation;
42
- // The state of an in-progress router.revalidate() calls
41
+ // The state of any in-progress router.revalidate() calls
43
42
  revalidation: RevalidationState;
44
- // Scroll position to restore to for the active Location, false if we
45
- // should not restore,m or null if we don't have a saved position
46
- // Note: must be enabled via router.enableScrollRestoration()
47
- restoreScrollPosition: number | false | null;
48
- // Proxied `resetScroll` value passed to router.navigate() (default true)
49
- resetScrollPosition: boolean;
50
43
  // Data from the loaders for the current matches
51
44
  loaderData: RouteData;
52
45
  // Data from the action for the current matches
@@ -55,6 +48,12 @@ interface RouterState {
55
48
  errors: RouteData | null;
56
49
  // Map of all active fetchers
57
50
  fetchers: Map<string, Fetcher>;
51
+ // Scroll position to restore to for the active Location, false if we
52
+ // should not restore, or null if we don't have a saved position
53
+ // Note: must be enabled via router.enableScrollRestoration()
54
+ restoreScrollPosition: number | false | null;
55
+ // Proxied `preventScrollReset` value passed to router.navigate()
56
+ preventScrollReset: boolean;
58
57
  }
59
58
  ```
60
59
 
@@ -98,6 +97,11 @@ router.fetch("key", "/page", {
98
97
  });
99
98
  ```
100
99
 
101
- ## Revalidation
100
+ ### Revalidation
102
101
 
103
102
  By default, active loaders will revalidate after any navigation or fetcher mutation. If you need to kick off a revalidation for other use-cases, you can use `router.revalidate()` to re-execute all active loaders.
103
+
104
+ [react-router]: https://reactrouter.com
105
+ [remix]: https://remix.run
106
+ [react-router-repo]: https://github.com/remix-run/react-router
107
+ [remix-routers-repo]: https://github.com/brophdawg11/remix-routers
package/dist/index.d.ts CHANGED
@@ -1,13 +1,8 @@
1
- import type { BrowserHistoryOptions, HashHistoryOptions, MemoryHistoryOptions } from "./history";
2
- import type { Router, RouterInit } from "./router";
3
1
  import { convertRoutesToDataRoutes } from "./utils";
4
2
  export type { ActionFunction, ActionFunctionArgs, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticRouteMatch, AgnosticRouteObject, TrackedPromise, FormEncType, FormMethod, JsonFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, Submission, } from "./utils";
5
- export { ErrorResponse, defer, generatePath, getToPathname, invariant, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, resolvePath, resolveTo, stripBasename, warning, } from "./utils";
6
- export type { BrowserHistory, HashHistory, History, InitialEntry, Location, MemoryHistory, Path, To, } from "./history";
3
+ export { AbortedDeferredError, ErrorResponse, defer, generatePath, getToPathname, invariant, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, resolvePath, resolveTo, stripBasename, warning, } from "./utils";
4
+ export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
7
5
  export { Action, createBrowserHistory, createPath, createHashHistory, createMemoryHistory, parsePath, } from "./history";
8
6
  export * from "./router";
9
- export declare function createMemoryRouter({ initialEntries, initialIndex, ...routerInit }: MemoryHistoryOptions & Omit<RouterInit, "history">): Router;
10
- export declare function createBrowserRouter({ window, ...routerInit }: BrowserHistoryOptions & Omit<RouterInit, "history">): Router;
11
- export declare function createHashRouter({ window, ...routerInit }: HashHistoryOptions & Omit<RouterInit, "history">): Router;
12
7
  /** @internal */
13
8
  export { convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes };