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

Feature/issue 935 native custom element ssr #943

Merged

Conversation

thescientist13
Copy link
Member

@thescientist13 thescientist13 commented Jun 5, 2022

Related Issue

resolves #935

Summary of Changes

  1. Introduced wcc + a default export syntax for SSR routes to emit a Web Component as body content
  2. Added test case for WCC and export default
  3. Added documentation re export default .... as HTMLElement and usage of WCC
  4. With WCC, don't have to use getFrontmatter.imports (YMMV) 🥳

Screen Shot 2022-06-05 at 9 18 39 AM

Will likely spin up a new release branch for this and any batched features we want to group for a release introducing these features.

TODO

  1. Needs fix from WCC for Node >= 16 support for CI - node modules (bare specifiers) are causing an unhandled filesystem exception wcc#43
  2. New build failure? Windows filesystem / interop thing?
         Generating graph of workspace files...
         2022-06-07T12:36:55.1362420Z Initializing project config
         2022-06-07T12:36:55.6002072Z Initializing project workspace contexts
         2022-06-07T12:36:55.6010831Z Generating graph of workspace files...
         2022-06-07T12:36:55.6019063Z building from local sources...
         2022-06-07T12:36:55.8982802Z { route: '/artists/' }
         2022-06-07T12:36:55.9040838Z 
         2022-06-07T12:36:55.9041705Z node:internal/process/promises:279
         2022-06-07T12:36:55.9043825Z             triggerUncaughtException(err, true /* fromPromise */);
         2022-06-07T12:36:55.9044317Z             ^
         2022-06-07T12:36:55.9054780Z TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file
         2022-06-07T12:36:55.9056972Z     at open (node:internal/fs/promises:451:10)
         2022-06-07T12:36:55.9057533Z     at Object.readFile (node:internal/fs/promises:797:20)
         2022-06-07T12:36:55.9058481Z     at getTagName (file:///D:/a/greenwood/greenwood/node_modules/wc-compiler/src/wcc.js:84:35)
         2022-06-07T12:36:55.9059303Z     at renderToString (file:///D:/a/greenwood/greenwood/node_modules/wc-compiler/src/wcc.js:130:32)
         2022-06-07T12:36:55.9060215Z     at executeRouteModule (file:///D:/a/greenwood/greenwood/packages/cli/src/lib/ssr-route-worker.js:26:38) {
         2022-06-07T12:36:55.9060867Z   code: 'ERR_INVALID_URL_SCHEME'
         2022-06-07T12:36:55.9061227Z }
         2022-06-07T12:36:55.9475381Z error Command failed with exit code 1.
       
  3. Need innerHTML support from wcc (static only mode) - support innerHTML in compiler for custom elements wcc#49
  4. Need to look into how this may impact prerender + puppeteer
    • basically, when puppeteer moves to plugin, WCC will just be the SSR default. But lit rendered for example, has a prerender option. Do we need to redefine prerender vs export? - will track as part of future release work
  5. Create / update relevant test cases
  6. Documentation (including components as pages)
  7. Support default export for Lit Renderer Plugin
  8. Extract / bundle SSR deps (e.g. native card) for some sort of interactivity example
    • would frontmatter imports work here? 🤩
  9. Wait for Bug/issue 940 static router breaking hybrid workspaces #942 and then remove router patch changes
  10. Did I accidentally overlap with Feature/issue 879 static export ssr routes #921?
    • yes, rolled back and will implement post puppeteer cutover
  11. setup v0.26.0 release branch and candidate features
    • Should have the ability to statically export server rendered routes as just HTML #879
    • puppeteer as a render plugin
    • will want to evaluate if we can improve how we are defining terms and experiences around SSR'd routes and prerender pages, and how it may differ across across various solutions now; WCC, Lit, Puppeteer, etc.Make sure it is not too confusing. Should also make sure it works across both solutions for HTML and JS.
    • Will want to update getting started, template blog, and projectevergreen repos to use WCC

Questions / New Issues

  1. For Lit export default, should find a way to get the tag name automatically, or maybe we don't need it all?
  2. Add SSR support into include HTML plugin? Or maybe we can deprecate the custom elements option now that we have WCC?
  3. Should / could we pre-render custom elements in markdown or in HTML (pages and template)? - yes, when we move puppeteer to a plugin and WCC is the default for prerender - puppeteer based renderer plugin and HTMLElement (WCC) as default renderer #954
  4. What to do about getTemplate and getPage? - Layouts (Templates) and Pages #955
    • default export allows you to use a custom element
    • in the future, maybe use HTMLElement for all of them?
    • keep strings simple for simple cases, wcc / HTMLElement for more advanced cases
  5. Introduce ASTs in Greenwood for HTML (and / or do better DOM parsing) - refactor HTML manipulation and generation #950
  6. Move puppeteer and related deps to a plugin, upgrade deps as well - puppeteer based renderer plugin and HTMLElement (WCC) as default renderer #954
    • how to execute arbitrary <script> logic / "setup" in a template for SSR (find example)
  7. Look into improving the Data story with Greenwood, be it fetch or GraphQL and if more can be done server side now, e.g. getData() and passed in as props or serialized as globalThis for hydration, a la add support for (progressive) hydration for compatible renderers (globalThis for state?) #880 , or consider APIs like getServerSideProps (SSR) vs getStaticProps (SSG) as part of a future data loading story? - Data Loading Strategies #952

@thescientist13 thescientist13 added documentation Greenwood specific docs CLI feature New feature or request labels Jun 5, 2022
@thescientist13 thescientist13 self-assigned this Jun 5, 2022
@thescientist13 thescientist13 force-pushed the feature/issue-935-native-custom-element-ssr branch from e7e975e to 8e4c1d9 Compare June 18, 2022 15:16
@thescientist13 thescientist13 added question Further information is requested SSR labels Jun 18, 2022
data.frontmatter = data.frontmatter || {};
data.frontmatter.imports = data.frontmatter.imports || [];

for (const entry in metadata) {
Copy link
Member Author

@thescientist13 thescientist13 Jun 19, 2022

Choose a reason for hiding this comment

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

I should probably make this conditional and opt-out by default, as part of #880

@thescientist13 thescientist13 marked this pull request as ready for review June 23, 2022 13:05
@thescientist13 thescientist13 added the Plugins Greenwood Plugins label Jun 23, 2022
@thescientist13 thescientist13 force-pushed the feature/issue-935-native-custom-element-ssr branch from ea78b2d to cdc7745 Compare July 1, 2022 00:12
@thescientist13 thescientist13 changed the base branch from master to release/0.26.0 July 1, 2022 00:32
@thescientist13 thescientist13 merged commit dec54f0 into release/0.26.0 Jul 1, 2022
@thescientist13 thescientist13 deleted the feature/issue-935-native-custom-element-ssr branch July 1, 2022 00:54
@thescientist13 thescientist13 mentioned this pull request Jul 1, 2022
19 tasks
thescientist13 added a commit that referenced this pull request Jul 27, 2022
* initial working local development example with wc-compiler for SSR native HTMLElement

* restore getTemplate to original location in SSR route worker

* bump latest version of wcc

* ensure passing of URLs to wcc

* upgrade WCC

* add support for prerendering SSR routes with default renderer WCC in favor of puppeteer

* document default export

* clean up console logging

* rollback premature static export feature

* use WCC to bundle SSR page routes
 automatically

* roll back native SSR auto hydration

* LitElement as SSR page with default export

* LitElement as a default export for pages

* clarify README example

* capture Lit exception for light DOM support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI documentation Greenwood specific docs feature New feature or request Plugins Greenwood Plugins question Further information is requested SSR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support server rendering a native HTMLElement
1 participant