Skip to content

Next.js integration: run Toolpad apps as React server components#3125

Draft
Janpot wants to merge 26 commits into
mui:masterfrom
Janpot:nextjs-integration
Draft

Next.js integration: run Toolpad apps as React server components#3125
Janpot wants to merge 26 commits into
mui:masterfrom
Janpot:nextjs-integration

Conversation

@Janpot

@Janpot Janpot commented Jan 25, 2024

Copy link
Copy Markdown
Member

WIP

Closes #3012

// ./app/my-toolpad-app/[[...slug]]/page.tsx
import * as React from 'react';
import { ToolpadApp } from '@mui/toolpad/next';

export default function ToolpadPage() {
  return <ToolpadApp base="/my-toolpad-app" dir="./myToolpadAppDir" />;
}

To Do:

  • directives in bundles
  • make client component run
  • make server component run
  • make bindings work
  • make backend API work (create an API shim based on serverActions)
  • chokidar/fsevents, sort out how to load it correctly (e.g. how to run it without needing chokidar in package.json and the custom webpack config)
  • @blitz/internal warning
  • latest-version generates webpack warnings
  • ...

@Janpot Janpot added the type: new feature Expand the scope of the product to solve a new problem. label Jan 25, 2024
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jan 29, 2024
dir: string;
}

export async function ToolpadApp({ base, dir = './toolpad' }: ToolpadAppServerProps) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the app decide which page to run? If it's the URL path concerning base, is it possible to abstract the URL from the app and modify the props as follows?

export interface ToolpadAppServerProps {
  dir: string;
  page: string;
}

It could help us dynamically render any page without worrying about the paths, giving user more control IMO. WDYT?

@Janpot Janpot Feb 9, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense. This is somewhat on hold because it depends on a bunch of low-level work that needs to happen first. We'll also have to abstract Toolpad routing to be able to plug in the Next.js router.

Another option I'm thinking of is to expose another component that renders a single page instead of the whole app.

@buremba buremba Feb 11, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option I'm thinking of is to expose another component that renders a single page instead of the whole app.

Yes, that would be even more useful for my use case where I have a backend to pull the MDX file and I can transform it on the fly render the page without even shell. If we can pass components and resources as well, the applications can utilize Toolpad's application model to render the generated pages in our app.

@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Apr 30, 2024
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Apr 30, 2024
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label May 2, 2024
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label May 5, 2024
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: out-of-date The pull request has merge conflicts and can't be merged. type: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[studio] Allow to embed a Toolpad Studio page as a React component

2 participants