HenriPodolski / Nextjs-webcomponent-SSR-widget

This code demonstrates how to create a webcomponent, which can be used as a widget, to be embedded in any web application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Next.js SSR webcomponent widgets PoC

This is a proof of concept, covering the following topics:

  • webcomponent that renders React components in webcomponents Shadow DOM
  • SSR and client side rehydration
  • Exposing the code fragments for the widget to work from the public folder of ./components-app/public, by using a webpack plugin that builds and bundles necessary dependencies and code only
  • Sharing the components between Next.js apps (and probably other apps) using import via URL (e.g. import MyComponent from 'https://example.com/my-component.js;)

Motivation

Using components from a Next.js application in another web application is a common use case. The code in this repository got you covered. Example: This Twitch followers widget is a separate website: My Twitch follower goal. If you want to embed it, into your website you will end up with an iframe solution. The demonstration in this repository, shows you how to implement something similar from your own Next.js application, but as a webcomponent that wraps existing React components and all that in SEO-friendly manner, because SSR is possible with that approach.

Overview

image

Resources

I used those posts, docs and implementations as a starting point and mixed it up, that it covers the requirements mentioned above:

About

This code demonstrates how to create a webcomponent, which can be used as a widget, to be embedded in any web application

License:MIT License


Languages

Language:TypeScript 51.6%Language:CSS 29.6%Language:SCSS 9.6%Language:JavaScript 7.4%Language:HTML 1.7%