Skip to content

Commit

Permalink
comments and TODOs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Feb 28, 2024
1 parent 200a40f commit 02dff52
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 54 deletions.
17 changes: 0 additions & 17 deletions packages/cli/src/lib/templating-utils.js
@@ -1,7 +1,6 @@
import fs from 'fs/promises';
import htmlparser from 'node-html-parser';
import { checkResourceExists } from './resource-utils.js';
// import { getPackageJson } from './node-modules-utils.js';

async function getCustomPageTemplatesFromPlugins(contextPlugins, templateName) {
const customTemplateLocations = [];
Expand Down Expand Up @@ -186,22 +185,6 @@ async function getUserScripts (contents, compilation) {
</script>
`);

// TODO get rid of lit polyfills in core
// https://github.com/ProjectEvergreen/greenwood/issues/728
// https://lit.dev/docs/tools/requirements/#polyfills
// if (process.env.__GWD_COMMAND__ === 'build') { // eslint-disable-line no-underscore-dangle
// const userPackageJson = await getPackageJson(context);
// const dependencies = userPackageJson?.dependencies || {};
// const litPolyfill = dependencies && dependencies.lit
// ? '<script src="/node_modules/lit/polyfill-support.js"></script>\n'
// : '';

// contents = contents.replace('<head>', `
// <head>
// ${litPolyfill}
// `);
// }

return contents;
}

Expand Down
10 changes: 0 additions & 10 deletions packages/cli/src/lifecycles/bundle.js
Expand Up @@ -224,20 +224,10 @@ async function bundleSsrPages(compilation) {
staticHtml = data.template ? data.template : await getPageTemplate(staticHtml, compilation.context, template, []);
staticHtml = await getAppTemplate(staticHtml, compilation.context, imports, [], false, title);
staticHtml = await getUserScripts(staticHtml, compilation);
// TODO seems like we are missing general purpose intercepting and optimization when bundling SSR pages
staticHtml = await (await interceptPage(new URL(`http://localhost:8080${route}`), new Request(new URL(`http://localhost:8080${route}`)), getPluginInstances(compilation), staticHtml)).text();
staticHtml = await (await htmlOptimizer.optimize(new URL(`http://localhost:8080${route}`), new Response(staticHtml))).text();
staticHtml = staticHtml.replace(/[`\\$]/g, '\\$&'); // https://stackoverflow.com/a/75688937/417806

// TODO prune graph of hydration data
// const g = [ ...compilation.graph ];

// g.forEach(page => {
// delete page.pageData;
// })

// compilation.graph = g;

// better way to write out this inline code?
await fs.writeFile(entryFileUrl, `
import { executeRouteModule } from '${normalizePathnameForWindows(executeModuleUrl)}';
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lifecycles/graph.js
Expand Up @@ -202,8 +202,8 @@ const generateGraph = async (compilation) => {
* template: page template to use as a base for a generated component
* title: a default value that can be used for <title></title>
* isSSR: if this is a server side route
* prerednder: if this should be statically exported
* prerednder: if this page needs hydration support
* prerender: if this should be statically exported
* hydration: if this page needs hydration support
*/
pages.push({
data: customData || {},
Expand Down
21 changes: 0 additions & 21 deletions packages/cli/src/plugins/resource/plugin-standard-html.js
Expand Up @@ -116,13 +116,6 @@ class StandardHtmlResource extends ResourceInterface {
ssrTemplate = result.template;
}

// if (result.hydrate) {
// matchingRoute.hydrate = result.hydrate;
// matchingRoute.pageData = result.pageData;

// console.log('Update Page', this.compilation.graph.find((node) => node.route === pathname));
// }

if (result.body) {
ssrBody = result.body;
}
Expand Down Expand Up @@ -209,20 +202,6 @@ class StandardHtmlResource extends ResourceInterface {
}
}

// if (matchingRoute.hydrate && matchingRoute.pageData) {
// const id = '__GWD_HYDRATION_DATA__';
// const { pageData } = matchingRoute;

// console.log('hydrate with page data =>', { pageData });

// body = body.replace('</head>', `
// <script type="application/json" id="${id}">
// ${JSON.stringify(pageData)}
// </script>
// </head>
// `);
// }

// give the user something to see so they know it works, if they have no content
if (body.indexOf('<content-outlet></content-outlet>') > 0) {
body = body.replace('<content-outlet></content-outlet>', `
Expand Down
5 changes: 1 addition & 4 deletions packages/plugin-renderer-lit/src/index.js
Expand Up @@ -14,19 +14,16 @@ class LitHydrationResource extends ResourceInterface {

async intercept(url, request, response) {
let body = await response.text();
const { pathname } = url;
const matchingRoute = this.compilation.graph.find((node) => node.route === pathname) || {};
console.log('LIT intercept =>', { url, matchingRoute });

// TODO would be nice not have to manually set module-shim
// when we drop support for import-map shim - https://github.com/ProjectEvergreen/greenwood/pull/1115
const type = process.env.__GWD_COMMAND__ === 'develop' // eslint-disable-line no-underscore-dangle
? 'module-shim'
: 'module';

// this needs to come first before any userland code
body = body.replace('<head>', `
<head>
<!-- this needs to come first before any userland code -->
<script type="${type}" src="/node_modules/@lit-labs/ssr-client/lit-element-hydrate-support.js"></script>
`);

Expand Down

0 comments on commit 02dff52

Please sign in to comment.