WordPress-like Plugins, but for Next.js

Join me on my journey of creating the Next.js WordPress-like Plugin System, an experiment that enhances Next.js applications by allowing easy installation and customization of plugins for features like Google Analytics, Social Login, and E-commerce. I'll showcase the unique features of the file-based plugin system, such as persistent storage per plugin, registration of components, routes, and functions, and a cross-plugin event system. The talk also shares the story of how and why I solved this problem to make developers' lives easier. Check out the experiment at https://github.com/gluestack/next-wordpress-plugins.

This talk has been presented at React Day Berlin 2023, check out the latest edition of this React Conference.

Watch video on a separate page

FAQ

The Confetti plugin adds a visual confetti effect to the website when it is added.

The key takeaways are: plugins enable co-location by feature, code abstraction shouldn't stop at packages, and copy-pasting is the future.

You can try the project by visiting the link provided in Sanket Sahu's talk or presentation.

NativeBase is a UI component library for React Native and React, co-created by Sanket Sahu.

Sanket Sahu is the co-creator of NativeBase, a UI component library for React Native and React, and he runs a company called GeekyAnts. He is currently working on the Glue Stack ecosystem.

The plugin system for Next.js works by co-locating all related files (routes, components, APIs, middleware) inside a single folder for each plugin. Adding or removing the folder adds or removes the functionality from the app.

Examples of plugins mentioned include a Hello World alert plugin, a coming soon page plugin, a chatbot plugin, an authentication system plugin, and a Confetti plugin.

The authentication system plugin registers routes, APIs, and middleware for login and logout functionalities. When added, it enables a fully working login system on the website; when removed, it takes away the authentication features.

The main concept is to build a WordPress-like plugin system for Next.js, where plugins can add or remove functionalities to a Next.js app by simply adding or removing folders.

The Glue Stack ecosystem is a project that focuses on creating a universal UI component library and tools around design systems, inspired by NativeBase version 3.

Sanket Sahu
Sanket Sahu
9 min
12 Dec, 2024

Comments

Sign in or register to post your comment.
Video Summary and Transcription
This Talk discusses the implementation of a plugin system for Next.js, similar to Wordpress. The plugin system allows for the co-location of different functionalities within their own modules. Plugins can be easily added or removed without affecting other parts of the website. The Talk also showcases a demo of the plugin system in action. The key takeaways include the benefits of co-locating features, the importance of code abstraction beyond packages, and the future of copy-pasting as a means of code reuse.

1. Building a Plugin System for Next.js

Short description:

I'm going to talk about how we can build a Wordpress-like plugin system for Next.js. Using this plugin system, we can co-locate different functionalities inside their own module system or namespace. The architecture includes a plugin system that acts as an intermediate step in Next.js, with its own store for routes and components. Let me show you a quick demo of how it works.

Hello React, dear Berlin, how's it going on? I'm Sanket Sahu, and I run a company called GeekyAnds, and I co-created a UI component library for React Native and React called Nativebase. These days I'm working on the Glue Stack ecosystem, which is on the lines of Nativebase version 3, universal UI component library, and tools around design system.

But today I'm going to talk about something else. It's about how we can build a Wordpress-like plugin system, but for Next.js. We got multiple things from PHP to React, and what explains better than this meme? So why not plugins? If you don't know yet, WordPress plugins are like a bunch of plugins which are segregated into folders, and as soon as you drop them into your project, we get like functional behavior, functionality changes, as soon as we add these plugins. Much like a Chrome extension, but a bit different when you compare it with like npm packages. In packages you have to install and then integrate yourself, while plugins, they add end user functionality.

So this is the dashboard of WordPress where we have multiple plugins. And this is an example from the old days how you can upload a plugin. This is an example of contact form, and as soon as you upload it, you have that feature available on your website. So why not for next? So using this plugin system, we can go from this folder structure where we have say, for example, the auth behavior or authentication distributed across your app, right? From say, pages slash login.js components, login form.js, and then API for the same thing, login and log out. Then middleware, and store, and a bunch of different things. So with the plugin system, we can co-locate all these things inside its own module system or namespace wherein as soon as you add or remove this plugin, then that auth behavior is removed from your app, right? So in this experiment, I have tried to do a file based plugin system inspired by WordPress, and these plugins enable visual and non-visual features per plugin. I've got the checklist from WordPress, which is a file based system, persistent store per plugin, register components, routes, functions, event system, and dependency management. Although this is just an experiment, I've tried to imitate these three behaviors, file system based, register components, and register routes. And this is how the architecture looks like. So we have this plugin system, and all the plugins talk to that. This plugin system adds as an intermediate step at different places in Next.js. We have a root provider for plugin system and we have some implementation in middleware.ts and somewhere in the all.tsx file. It maintains its own store for routes and components. So, yeah, this is how the architecture looks like. Yeah, so some time for some demo. Great. So let me just try this. Okay, so how does the code look like? So we have a plugins folder and as soon as we install or add these folders, we get those functionality. So a quick demo would be this one. So this is a Next.js app, which has the plugin system installed. So what I've done is let's remove all these plugins into the download folder. And if I go and refresh this, so this is now a website which does not have any plugins installed. Say, if I want to do say, a Hello World plugin, which essentially adds an alert message, as soon as we drop it, we see this Hello World being activated.

2. Adding Plugins to Next.js

Short description:

This plugin allows us to add different functionalities into Next.js as separate plugins. We can add components and routes specific to each plugin, such as a Hello World behavior or a coming soon page. The plugins are independent and can be added or removed without affecting other parts of the website. For example, we can add a chatbot or an authentication system, which includes routes, middleware, and a fully working login system.

What does this do? So this plugin is all here, I mean, all located inside this, and it adds a simple Hello World behavior into this. Let's see the code for this one. So we have plugins and then Hello World. So this implements iplugin, and we have a boot method. If type of window is not undefined, that means if it's a browser show the alert Hello World. So we've just added this folder and it automatically added the Hello World alert message on all the pages.

This is just a simple example, but we can go beyond this, for example, say, coming soon page, I want to create a coming soon page with a plugin. So we can just remove Hello World for a while, and then we can get entire coming soon route here as soon as we do it. So this is all inside this, the coming soon folder all together. So if you see this, we have a register route function, which we are calling in our coming soon page plugin. And yeah, we have a route and a component against that. And this component is over here. And I've used glue stack UI for the styling. And it has some assets and all those things.

So this page, this plugin is independent. You can add or remove this without having any dependency on separate things. So we have a chatbot for example. As soon as we add it, we get this chatbot over here, which is completely decoupled from your actual page logic and then it appears everywhere, for example. Then we have say authentication system. So we don't have anything like login over here, for example. But as we add this entire Auth plugin over here, this enables and makes the entire website to have a login system here and it has a fully working login system. It has an API, it has the routes, middleware and everything. Let's quickly see that too. In the Auth plugin we are registering a few of the routes like login and home, we are registering API login, API logout and we are also registering a middleware that checks for login. Yeah, so all these things now work. Let me see what's the username and password so I can go ahead and try logging in. Okay, so yeah, so let's see and let's see. Okay, so this works and now slash home is restricted. If you are logged in, then only it shows up. If not, so all the logic is added into this.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Routing in React 18 and Beyond
React Summit 2022React Summit 2022
20 min
Routing in React 18 and Beyond
Top Content
Routing in React 18 brings a native app-like user experience and allows applications to transition between different environments. React Router and Next.js have different approaches to routing, with React Router using component-based routing and Next.js using file system-based routing. React server components provide the primitives to address the disadvantages of multipage applications while maintaining the same user experience. Improving navigation and routing in React involves including loading UI, pre-rendering parts of the screen, and using server components for more performant experiences. Next.js and Remix are moving towards a converging solution by combining component-based routing with file system routing.
A Practical Guide for Migrating to Server Components
React Advanced 2023React Advanced 2023
28 min
A Practical Guide for Migrating to Server Components
Top Content
Watch video: A Practical Guide for Migrating to Server Components
React query version five is live and we'll be discussing the migration process to server components using Next.js and React Query. The process involves planning, preparing, and setting up server components, migrating pages, adding layouts, and moving components to the server. We'll also explore the benefits of server components such as reducing JavaScript shipping, enabling powerful caching, and leveraging the features of the app router. Additionally, we'll cover topics like handling authentication, rendering in server components, and the impact on server load and costs.
The New Next.js App Router
React Summit 2023React Summit 2023
27 min
The New Next.js App Router
Top Content
Watch video: The New Next.js App Router
Today's Talk is about the Next.js App Router, which has evolved over the years and is now a core feature of Next.js. The Talk covers topics such as adding components, fetching remote data, and exploring layouts. It also discusses submitting form data, simplifying code, and reusing components. The App Router allows for coexistence with the existing pages router and enables data fetching at the layout level using React Server Components.
You Don’t Know How to SSR
DevOps.js Conf 2024DevOps.js Conf 2024
23 min
You Don’t Know How to SSR
The Talk covers the speaker's personal journey into server-side rendering (SSR) and the evolution of web development frameworks. It explores the use of jQuery for animations in SSR, the challenges faced in integrating React with Umbraco, and the creation of a custom SSR framework. The Talk also discusses the benefits of Next.js and the use of serverless artifacts for deployment. Finally, it highlights the features of Astro, including its function per route capability.
How to properly handle URL slug changes in Next.js
TypeScript Congress 2022TypeScript Congress 2022
10 min
How to properly handle URL slug changes in Next.js
Top Content
This Talk explains how to handle URL slug changes in Next.js by using the getStaticPaths and getStaticProps methods. It covers implementing redirects and provides a solution to eliminate the need for editors to perform additional steps. The approach involves tracking URL slug changes and issuing proper redirects. The speaker encourages the audience to reach out with any questions or experiences with handling URL slugs.
Killing BFFs with GraphQL and Next.js
React Advanced 2021React Advanced 2021
21 min
Killing BFFs with GraphQL and Next.js
Top Content
This talk discusses the challenges and benefits of using Backend for Frontends (BFFs) and microservices in software development. It highlights how Next.js can simplify the creation of BFFs and unify the gateway for microservices. The talk also emphasizes the advantages of Next.js API routes in simplifying the development, deployment, and maintenance of APIs. It showcases the implementation of a BFF using Next.js and API routes, and the extension of API routes in an executable way. The speaker also mentions launching a course on using Next.js API routes for building a serverless GraphQL API.

Workshops on related topic

AI for React Developers
React Advanced 2024React Advanced 2024
142 min
AI for React Developers
Featured Workshop
Eve Porcello
Eve Porcello
Knowledge of AI tooling is critical for future-proofing the careers of React developers, and the Vercel suite of AI tools is an approachable on-ramp. In this course, we’ll take a closer look at the Vercel AI SDK and how this can help React developers build streaming interfaces with JavaScript and Next.js. We’ll also incorporate additional 3rd party APIs to build and deploy a music visualization app.
Topics:- Creating a React Project with Next.js- Choosing a LLM- Customizing Streaming Interfaces- Building Routes- Creating and Generating Components - Using Hooks (useChat, useCompletion, useActions, etc)
Tracing: Frontend Issues With Backend Solutions
React Summit US 2024React Summit US 2024
112 min
Tracing: Frontend Issues With Backend Solutions
Featured WorkshopFree
Lazar Nikolov
Sarah Guthals
2 authors
Frontend issues that affect your users are often triggered by backend problems. In this workshop, you’ll learn how to identify issues causing slow web pages and poor Core Web Vitals using tracing.
Then, try it for yourself by setting up Sentry in a ready-made Next.js project to discover performance issues including slow database queries in an interactive pair-programming session.
You’ll leave the workshop being able to:- Find backend issues that might be slowing down your frontend apps- Setup tracing with Sentry in a Next.js project- Debug and fix poor performance issues using tracing
This will be a live 2-hour event where you’ll have the opportunity to code along with us and ask us questions.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Next.js 13: Data Fetching Strategies
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
Top Content
WorkshopFree
Alice De Mauro
Alice De Mauro
- Introduction- Prerequisites for the workshop- Fetching strategies: fundamentals- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)- Test your build and serve it on Vercel- Future: Server components VS Client components- Workshop easter egg (unrelated to the topic, calling out accessibility)- Wrapping up
From Todo App to B2B SaaS with Next.js and Clerk
React Summit US 2023React Summit US 2023
153 min
From Todo App to B2B SaaS with Next.js and Clerk
Top Content
WorkshopFree
Dev Agrawal
Dev Agrawal
If you’re like me, you probably have a million side-project ideas, some that could even make you money as a micro SaaS, or could turn out to be the next billion dollar startup. But how do you know which ones? How do you go from an idea into a functioning product that can be put into the hands of paying customers without quitting your job and sinking all of your time and investment into it? How can your solo side-projects compete with applications built by enormous teams and large enterprise companies?
Building rich SaaS products comes with technical challenges like infrastructure, scaling, availability, security, and complicated subsystems like auth and payments. This is why it’s often the already established tech giants who can reasonably build and operate products like that. However, a new generation of devtools are enabling us developers to easily build complete solutions that take advantage of the best cloud infrastructure available, and offer an experience that allows you to rapidly iterate on your ideas for a low cost of $0. They take all the technical challenges of building and operating software products away from you so that you only have to spend your time building the features that your users want, giving you a reasonable chance to compete against the market by staying incredibly agile and responsive to the needs of users.
In this 3 hour workshop you will start with a simple task management application built with React and Next.js and turn it into a scalable and fully functioning SaaS product by integrating a scalable database (PlanetScale), multi-tenant authentication (Clerk), and subscription based payments (Stripe). You will also learn how the principles of agile software development and domain driven design can help you build products quickly and cost-efficiently, and compete with existing solutions.
Create a Visually Editable Next.js Website Using React Bricks, With Blog and E-commerce
React Summit 2023React Summit 2023
139 min
Create a Visually Editable Next.js Website Using React Bricks, With Blog and E-commerce
Top Content
WorkshopFree
Matteo Frana
Matteo Frana
- React Bricks: why we built it, what it is and how it works- Create a free account- Create a new project with Next.js and Tailwind- Explore the directory structure- Anatomy of a Brick- Create a new Brick (Text-Image)- Add a title and description with RichText visual editing- Add an Image with visual editing- Add Sidebar controls to edit props (padding and image side)- Nesting Bricks using the Repeater component- Create an Image gallery brick- Publish on Netlify or Vercel- Page Types and Custom fields- Access Page meta values- Internationalization- How to reuse content across pages: Stories and Embeds- How to create an E-commerce with Products’ data from an external database and landing pages created visually in React Bricks- Advanced enterprise features: flexible permissions, locked structure, custom visual components