Add a demo Next.js app

Created on 25 October 2023, 7 months ago
Updated 11 March 2024, 3 months ago

Problem/Motivation

This is a child issue of #3393032: Add a server-side rendered (SSR or RSC) build for Umami JSX β†’ . As one implementation of that issue, I think it would be awesome to create a demo Next.js app that implements all of the Drupal templates/components as React Server Components, and also showcases how client components can be incorporated too once #3393014: Add some client-side interactivity to Umami JSX β†’ is done.

This might require creating a subtheme of Umami JSX (perhaps named Umami Next.js) that overrides templates that require specific customization for Next.js: for example, we might need to override html.html.twig, but maybe not much more than that.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Fixed

Version

1.0

Component

Umami Next.js Demonstration Theme

Created by

πŸ‡ΊπŸ‡ΈUnited States effulgentsia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @effulgentsia
  • πŸ‡ΊπŸ‡ΈUnited States effulgentsia

    I think this will take a bunch of work, but it will be pretty amazing once done! I think it'll be helpful to do this in steps. Here's the first few steps I propose (for each step after the first, I'd be happy to merge a working MR to the main branch):

    1. Go through the Next.js tutorial (all 16 pages). It's got some good information in there specifically targeted to Next.js 13 (when support for RSC was added via their new "app" router) and 14. Or at least, I feel like I learned a bunch by going through it.
    2. Create an initial app within demo/themes/umami_nextjs/app (no need to create the Drupal theme yet, at this point let's just start with the next.js app only). Give it a root layout (for the <html> and <body> tags but not yet anything in the body other than {children}) and a catch-all route that all URLs will go to. At this step, just have this route render <div>{url}</div> where url is the URL that you're on, which you can reconstruct with the params and searchParams props.
    3. Next, change the route to instead of displaying the URL, to fetch that URL (adjusted for host and port) from Drupal. For example, if the Next.js app is on localhost:3000 and the Drupal site is on drupal.dev, then if in the browser you visit localhost:3000/a/b/c, the route should fetch the content of drupal.dev/a/b/c. At this step, it's better for the Drupal site to be using the regular Umami theme, not the Umami JSX theme. Once the route has that content, use happy-dom to get the innerHTML of just the div with the data-off-canvas-main-canvas attribute. Have the route render that innerHTML into a div via the dangerouslySetInnerHTML prop. Optionally, to make this look like Umami, copy the <link> tags from a "View source" of the Drupal site into the <head> section of the app's root layout. The hrefs of these link tags would need to be adjusted to use the Drupal site's URL, since at this point the next.js app can't yet serve these CSS files. At this point, it's now hopefully possible to go to localhost:3000 and click around to navigate to different pages and see their content.
    4. Next, replace dangerouslySetInnerHTML with using hyperscriptify to convert the HTML into a React element.
    5. Next, switch the Drupal site to use the Umami JSX theme, and wire up the call to hyperscriptify() to pass in the components map.
    6. Once we get this far, let's regroup to figure out the rest. For example, we'll need to figure out how to best get all the CSS served by Next.js (including both the global CSS still managed by Drupal and the Linaria CSS). But one feature I'm really looking forward to hopefully be able for us to try and have it "just work" is being able to map the 'a' element to Next.js's Link component in order to enable single-page-app behavior instead of full page refreshes.
  • First commit to issue fork.
  • Merge request !16Draft: WIP: Nextjs implementation β†’ (Open) created by hooroomoo
  • Merge request !17Add a demo Next JS app β†’ (Merged) created by hooroomoo
  • πŸ‡ΊπŸ‡ΈUnited States hooroomoo

    hooroomoo β†’ changed the visibility of the branch 1.0.x to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States hooroomoo

    hooroomoo β†’ changed the visibility of the branch 3396649-add-a-demo to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States effulgentsia

    Turns out, we might not actually need a subtheme for this.

  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI

    It is very possible some of the MR feedback is for my own code from the first JSX demo that has been ported to the next demo.

  • Merge request !18Next with debug tool β†’ (Open) created by hooroomoo
  • πŸ‡ΊπŸ‡ΈUnited States effulgentsia

    Just doing some issue queue organization. Raising the priority to Critical just to add transparency that it's a key feature for an MVP.

  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States hooroomoo

    For 'nextjs' branch

  • Pipeline finished with Skipped
    3 months ago
    #104390
  • Status changed to Fixed 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI

    Merged. This is very nice. We can fine tune etc in other issues, this big buddy deserves to get in and inspire work in other issues.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024