-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v7 - types not being exported by react-router #12431
Comments
Same here, temporarily import "react-router/dist/production" instead of "react-router" to have types. But it breaks running... |
I'm not able to reproduce this. I'm wondering if it's something specific to your |
Hi @brookslybrand , I hope the functions/types below can be exported from react-router as we are using them in our current code. import { History, Listener } from "@remix-run/router/history"; |
These all come from history (a dependency of I'm not sure why we were re-exporting them before/why we stopped now (maybe @brophdawg11 has some context) I'm a little skeptical you need these though if you are already using |
Hey mate, We use it for module federation. I tried importing these features directly from the history package, but it is not included as part of react-router v7 import type { Theme } from "@mui/material";
import type { History, Listener } from "@remix-run/router/history";
import { createMemoryHistory, createBrowserHistory } from "@remix-run/router";
import { createRoot } from "react-dom/client";
import App from "./App";
import { wsClient } from "./config/apollo/wsClient";
import type { User } from "./graphql/graphqlTypes";
export interface IParentProps {
onParentNavigate?: Listener;
defaultHistory: History;
initialPath?: string;
user?: User;
theme?: Theme;
}
const mount = (
elem: any,
{ onParentNavigate, defaultHistory, initialPath, ...rest }: IParentProps
) => {
const childHistory =
defaultHistory ||
createMemoryHistory({
initialEntries: [initialPath!]
});
if (onParentNavigate) {
// update child history when parent history changes
childHistory.listen(onParentNavigate);
}
// reset websocket
wsClient.resetStore();
const root = createRoot(elem);
root.render(<App {...rest} />);
return {
// give parent a handle, when child history changes, update the parent history
onChildNavigate: (currentHistory: History) => {
const nextPathname = currentHistory.location.pathname;
const currentPathname = childHistory.location.pathname;
if (nextPathname !== currentPathname) {
childHistory.push(nextPathname);
}
}
};
};
export { mount };
if (process.env.NODE_ENV === "development") {
const devRoot = document.querySelector("#child-root");
if (devRoot) {
mount(devRoot, {
defaultHistory: createBrowserHistory()
});
}
} |
@kelvin2200 Can you provide a reproduction of your issue? I'm also unable to reproduce it. One potential issue is that the @cjnoname The deep imports from I think we stopped exporting the As for module federation usages, we released the |
Hi @brophdawg11, Thanks for helping to export UNSAFE_ functions. I will read through the documents you shared. |
@brophdawg11 the reproduction is in the code I posted. What I did in the past, was to import I am using react-router in a minimal form, in an implementation with react-relay for render-as-you-fetch patterns and preloading queries. Furthermore, (even though this may be off-topic)... WHY did you guys turn this into a (yet another) framework? |
As a workaround for |
Apologies for the delay - I was on paternity leave at the end of the year so wasn't able to keep up with github notifications - and only say today's comment in my inbox.
As both Brooks and I said, we cannot reproduce it from the code you provided so we will need a working reproduction to dig further. From the error screenshot it seems like it might have something to do with your
Your reproduction code is using
We didn't. We merged an existing framework (Remix) into this repository and made it available in React Router v7 as a new and completely optional approach. React Router in library mode is effectively the same as v6.
We've outlined the features the vite plugin (framework mode) provides in the upgrade guider: https://reactrouter.com/upgrading/component-routes#features |
Hello folks, is there any way to use matchRoutes utility with the array of routes returned from the app/routes.ts file while using Framework mode? |
This issue has been automatically closed because we haven't received a response from the original author 🙈. This automation helps keep the issue tracker clean from issues that aren't actionable. Please reach out if you have more information for us! 🙂 |
I am trying to infer a type that is explicitly not being exported by the lib. The TS error makes sense and it should happen regardless of the package manager used. I patched the lib, exported that type, and the error went away. May I ask, why is this so controversial? Why can't u guys just export the damn type. It seems I'm not the only one in need of it. FFs....it's just a type. |
Nothing here is controversial. We asked for a reproduction, didn't receive one, and eventually our bot closed the issue due to the lack of a reproduction.
This type of tone isn't going to win you any favors 🙃 |
initial workaround for server side code: import { RouteConfigEntry } from "@react-router/dev/routes";
import { matchRoutes } from "react-router";
import routes from "@/routes"; // importing your routes file here
// Extract the type from matchRoutes function parameter
type AgnosticRouteObject = Parameters<typeof matchRoutes>[0][0];
export function convertRouteConfig(entries: RouteConfigEntry[]): AgnosticRouteObject[] {
return entries.map((entry) => {
const routeObj: AgnosticRouteObject = {
index: entry.index,
path: entry.path,
caseSensitive: entry.caseSensitive,
id: entry.id,
};
if (entry.children) {
routeObj.children = convertRouteConfig(entry.children);
}
return routeObj;
});
}
...
const matches = matchRoutes(convertRouteConfig(routes), history.location.pathname); |
I'm using React Router as a...
library
Reproduction
System Info
Used Package Manager
yarn
Expected Behavior
I expect to be able to re-export any type that I can infer
Actual Behavior
The text was updated successfully, but these errors were encountered: