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

warnings emitted about undefined page level custom element tags when pre-rendering SSR pages #988

Closed
1 of 5 tasks
thescientist13 opened this issue Oct 22, 2022 · 2 comments · Fixed by #1212 or #1208
Closed
1 of 5 tasks
Assignees
Labels
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Oct 22, 2022

Type of Change

  • New Feature Request
  • Documentation / Website
  • Improvement / Suggestion
  • Bug
  • Other (please clarify below)

Summary

When using an SSR page + prerender config to generate HTML

import fetch from 'node-fetch';
import '../components/cast-and-crew/cast-and-crew.js';
import '../components/upcoming-events/upcoming-events.js';
import '../components/spotify-playlist/spotify-playlist.js';

export default class Home extends HTMLElement {
  async connectedCallback() {
    const events = (await fetch('https://.../api/events')
      .then(resp => resp.json()))

    this.innerHTML = `
      <tt-upcoming-events
        events='${JSON.stringify(events).replace(/'/g, '\\"')}'
      ></tt-upcoming-events>

      <tt-cast-crew></tt-cast-crew>
      <tt-spotify-playlist></tt-spotify-playlist>
    `;
  }
}

I keep getting warnings in the console that those custom elements for the page are not defined

% yarn clean && yarn build
yarn run v1.22.19
$ rimraf public/ .greenwood/ ./storybook-static
✨  Done in 0.12s.
yarn run v1.22.19
$ NODE_ENV=production greenwood build
-------------------------------------------------------
Welcome to Greenwood (v0.26.1) ♻️
-------------------------------------------------------
Initializing project config
Initializing project workspace contexts
Generating graph of workspace files...
building from local sources...
Running Greenwood with the build command.
pages to generate 
 /
 /404/
generated page... /404/
@@@@ /Users/analogstudios/Workspace/analogstudios/repos/www.tuesdaystunes.tv/.greenwood/404.html
WARNING: customElement <tt-upcoming-events> is not defined.  You may not have imported it yet.
generated page... /
@@@@ /Users/analogstudios/Workspace/analogstudios/repos/www.tuesdaystunes.tv/.greenwood/index.html
WARNING: customElement <tt-cast-crew> is not defined.  You may not have imported it yet.
WARNING: customElement <tt-spotify-playlist> is not defined.  You may not have imported it yet.
success, done generating all pages!

warn - You have enabled the JIT engine which is currently in preview.
warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
copying directory... src/assets
copying file... src/assets/tuesdays-tunes.webp
copying file... src/assets/fonts/coop-bl.woff2
copying file... src/assets/icons/facebook.svg
copying file... src/assets/icons/spotify.svg
copying file... src/assets/icons/youtube.svg
copying file... src/favicon.ico
copying file... .greenwood/graph.json
✨  Done in 1.50s.

Details

What's interesting is that the page still gets fully generated as expected? All the HTML from those custom elements are visible in the output so "technically" it is a bug but also working as expected? 😅 :what:
AnalogStudiosRI/www.tuesdaystunes.tv#49


OUTDATED
To this point above, I think the technicality we're experiencing is due to during the graph lifecycle, we boot up each page in order to see if it has front matter, so I can see all the code and custom elements loading before the build process even happens.

% yarn clean && yarn build
yarn run v1.22.19
$ rimraf public/ .greenwood/ ./storybook-static
✨  Done in 0.15s.
yarn run v1.22.19
$ NODE_ENV=production greenwood build
-------------------------------------------------------
Welcome to Greenwood (v0.26.1) ♻️
-------------------------------------------------------
Initializing project config
Initializing project workspace contexts
Generating graph of workspace files...
building from local sources...
!!!!!! FOUND A DEPENDENCY!!!!!!! file:///Users/analogstudios/Workspace/analogstudios/repos/www.tuesdaystunes.tv/src/components/cast-and-crew/cast-and-crew.js
!!!!!! FOUND A DEPENDENCY!!!!!!! file:///Users/analogstudios/Workspace/analogstudios/repos/www.tuesdaystunes.tv/src/components/upcoming-events/upcoming-events.js
!!!!!! FOUND A DEPENDENCY!!!!!!! file:///Users/analogstudios/Workspace/analogstudios/repos/www.tuesdaystunes.tv/src/components/spotify-playlist/spotify-playlist.js
Running Greenwood with the build command.
pages to generate 
 /
 /404/
generated page... /404/
@@@@ /Users/analogstudios/Workspace/analogstudios/repos/www.tuesdaystunes.tv/.greenwood/404.html
!!!!!! FOUND A DEPENDENCY!!!!!!! file:///Users/analogstudios/Workspace/analogstudios/repos/www.tuesdaystunes.tv/src/components/cast-and-crew/cast-and-crew.js
!!!!!! FOUND A DEPENDENCY!!!!!!! file:///Users/analogstudios/Workspace/analogstudios/repos/www.tuesdaystunes.tv/src/components/upcoming-events/upcoming-events.js
!!!!!! FOUND A DEPENDENCY!!!!!!! file:///Users/analogstudios/Workspace/analogstudios/repos/www.tuesdaystunes.tv/src/components/spotify-playlist/spotify-playlist.js
WARNING: customElement <tt-upcoming-events> is not defined.  You may not have imported it yet.
generated page... /
@@@@ /Users/analogstudios/Workspace/analogstudios/repos/www.tuesdaystunes.tv/.greenwood/index.html
WARNING: customElement <tt-cast-crew> is not defined.  You may not have imported it yet.
WARNING: customElement <tt-spotify-playlist> is not defined.  You may not have imported it yet.
success, done generating all pages!

warn - You have enabled the JIT engine which is currently in preview.
warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
copying directory... src/assets
copying file... src/assets/tuesdays-tunes.webp
copying file... src/assets/icons/facebook.svg
copying file... src/assets/icons/spotify.svg
copying file... src/assets/icons/youtube.svg
copying file... src/assets/fonts/coop-bl.woff2
copying file... src/favicon.ico
copying file... .greenwood/graph.json
✨  Done in 1.25s.

So that could explain why these modules are already loaded but I thought since they were all in a worker, they would be self contained???? 😕


I guess this implies that SSR us not happening for page level custom elements like in templates/app.html. I wonder if it means we should SSR everything in development, defer to browser rendering as much as possible? That would mean honoring data-gwd-opt and a bunch of optimizations.

I suppose this could be a devServer option to optimize in development to sanity test, and make it false by default?

@thescientist13 thescientist13 added bug Something isn't working P0 Critical issue that should get addressed ASAP CLI SSR v0.26.2 labels Oct 22, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone Oct 22, 2022
@thescientist13 thescientist13 self-assigned this Oct 22, 2022
@thescientist13
Copy link
Member Author

So did some debugging #989 (comment) and found the root cause. Basically we are over-rendering the page contents, twice to be exactly. So not passing the page deps was keeping it from behaving like this.

Will want to re-think this approach and optimize to see if we can avoid double SSR for pages, might want to attach to v0.27.0 release?

@thescientist13 thescientist13 mentioned this issue Oct 23, 2022
27 tasks
@thescientist13 thescientist13 changed the title warnings emitted about undefined custom element tags when pre-rendering SSR pages warnings emitted about undefined page level custom element tags when pre-rendering SSR pages Oct 23, 2022
@thescientist13 thescientist13 moved this from 📋 Backlog to 🏗 In progress in [Greenwood] Phase 9 - Standards and Conventions Oct 29, 2022
@thescientist13 thescientist13 added bug Something isn't working and removed bug Something isn't working P0 Critical issue that should get addressed ASAP labels Nov 22, 2022
@thescientist13 thescientist13 moved this from 🏗 In progress to 🔖 Ready in [Greenwood] Phase 9 - Standards and Conventions Dec 16, 2022
@thescientist13
Copy link
Member Author

thescientist13 commented Dec 2, 2023

Hmm, seeing this now, and this is actually a different issue, but in the greenwood-getting-started repo now too, seemingly after the v0.29.0 release? 🤔

➜  greenwood-getting-started git:(master) npm run build

> greenwood-getting-started@1.0.0 build
> greenwood build

-------------------------------------------------------
Welcome to Greenwood (v0.29.0) ♻️
-------------------------------------------------------
Initializing project config
Initializing project workspace contexts
Generating graph of workspace files...
building from local sources...
Running Greenwood with the build command.
pages to generate
 /blog/first-post/
 /blog/second-post/
 /
 /404/
No custom element class found for this file
generated page... /blog/first-post/
No custom element class found for this file
generated page... /blog/second-post/
No custom element class found for this file
generated page... /
No custom element class found for this file
generated page... /404/
success, done generating all pages!
bundling static assets...
optimizing static pages....
copying directory... src/assets/
copying file... src/assets/greenwood-logo.png
copying file... src/favicon.ico
copying file... .greenwood/manifest.json

I see why now... with the addition of #1135 and us persisting the configuration to the document (and this would likely also apply to GraphQL or static router)

<script>
  globalThis.__GWD_BASE_PATH__ = '';
</script>    

This is now being passed as a dependency URL to WCC in renderToHtml and because this script doesn't contain a custom element, it will "trip" this code in WCC which causes the console.log.

So the question is:

  1. Should WCC just ignore / swallow this? Would these chunks be needed to supplement dependencies passed into WCC?
  2. Or should Greenwood be smart enough to figure out the right scripts to send to WCC?

@thescientist13 thescientist13 linked a pull request Mar 16, 2024 that will close this issue
20 tasks
@thescientist13 thescientist13 moved this from 🔖 Ready to 👀 In review in [Greenwood] Phase 9 - Standards and Conventions Jun 18, 2024
@thescientist13 thescientist13 linked a pull request Jun 22, 2024 that will close this issue
39 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment