Skip to content
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

[RFC] Rename AppProvider export for Next.js and react-router integrations #4319

Open
garryxiao opened this issue Oct 27, 2024 · 7 comments · May be fixed by #4553
Open

[RFC] Rename AppProvider export for Next.js and react-router integrations #4319

garryxiao opened this issue Oct 27, 2024 · 7 comments · May be fixed by #4553
Assignees
Labels
RFC Request For Comments scope: toolpad-core Abbreviated to "core"

Comments

@garryxiao
Copy link
Contributor

garryxiao commented Oct 27, 2024

What's the problem?

I followed the example and found the example fails (keep refresh the whole page when click the nested links) when import the "AppProvider" with

import { AppProvider } from "@toolpad/core/AppProvider";

but works when use

import { AppProvider } from "@toolpad/core/react-router-dom"'

It's very confusing with the same name export but actual different. And not type 'Navigation' found of the 'core-vite' example line:

import { AppProvider, type Navigation } from '@toolpad/core/react-router-dom';

What are the requirements?

No response

What are our options?

Rename the export name and mention it in the documentation would be perfect.

Proposed solution

No response

Resources and benchmarks

No response

Search keywords:

@garryxiao garryxiao added RFC Request For Comments status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 27, 2024
@Janpot
Copy link
Member

Janpot commented Oct 28, 2024

thank you, can you add a proposal for the new names under the options section?

When we reach consensus, would you be interested in contributing this change?

@Janpot Janpot changed the title [RFC] Confusion between [import { AppProvider } from "@toolpad/core/react-router-dom"] and [import { AppProvider } from "@toolpad/core/AppProvider";] [RFC] Rename AppProvider export for Next.js and react-router integrations Oct 28, 2024
@apedroferreira
Copy link
Member

apedroferreira commented Oct 28, 2024

One option that I considered before and thought about bringing up for consideration again was to export a hook to create the router with React Router, to be passed as a prop to the standard AppProvider, instead of having a specific AppProvider for React Router.
This requires creating an extra component sometimes because the hook requires the React Router context around it, but when using createBrowserRouter instead of BrowserRouter a separate component with the AppProvider is already needed anyway, and this approach probably makes more sense.

Besides that or a possible rename, we can also consider exporting all the types from the standard AppProvider in the other AppProvider alternatives.

@garryxiao
Copy link
Contributor Author

My idea is to add a type declaration file called "AppProviderTypes.ts", export it globally and remove the "AppProvider" export at the same time, but the changes are huge. Or add "AppProviderComponent.ts", keep the types in "AppProvider.ts", that would be a better idea.

@Janpot
Copy link
Member

Janpot commented Oct 29, 2024

I think we eventually want to be able to do more in the next.js app provider than just routing. A hook may be a bit limited in that sense?

I'm not sure it's a good idea to export the same interfaces from multiple places (barrel filles excluded). We don't do that anywhere, it could become confusing.

I think renaming it to something like AppRouterAppProvider makes quite a lot of sense, it would be analog to the AppRouterCacheProvider we have in @mui/material-nextjs.

@apedroferreira
Copy link
Member

I think we eventually want to be able to do more in the next.js app provider than just routing. A hook may be a but limited in that sense?

For the Next.js AppProvider that's probably true, but for the React Router integration I wasn't so sure.
But it's just something we could consider and discuss later. I guess that supporting different types of app with different AppProviders might be more consistent overall too.

I think renaming it to something like AppRouterAppProvider makes quite a lot of sense, it would be analog to the AppRouterCacheProvider we have in @mui/material-nextjs.

Ok, I was thinking about something like ReactRouterAppProvider for the React Router integration so we could follow that pattern?

I'm not sure it's a good idea to export the same interfaces from multiple places (barrel filles excluded). We don't do that anywhere, it could become confusing.

Ok, we can keep types as they are for now, the renaming would already help reduce the confusion.

@apedroferreira apedroferreira added scope: toolpad-core Abbreviated to "core" and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 29, 2024
@apedroferreira apedroferreira self-assigned this Oct 29, 2024
@EstherPerelmanCommit
Copy link

we lately created a new project with the toolpad and mistakenly imported the AppProvider from the wrong url, this was vaery hard to find out! each time we navigated between routes in the sidebar the app reloaded instead smoothly navigation

@apedroferreira
Copy link
Member

Note: make sure we also solve the confusion in #4513 with this.

@prakhargupta1 prakhargupta1 moved this from Backlog to Planned in MUI Toolpad public roadmap Dec 9, 2024
@apedroferreira apedroferreira moved this from Planned to In progress in MUI Toolpad public roadmap Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments scope: toolpad-core Abbreviated to "core"
Projects
Status: In progress
Development

Successfully merging a pull request may close this issue.

4 participants