ProjectEvergreen / greenwood

Greenwood is your workbench for the web, embracing web standards from the ground up to empower your stack from front to back.
https://www.greenwoodjs.io
MIT License
96 stars 9 forks source link

SSR pages are not getting their resources (`<link>` / `<style>` / `<script>` tags) bundled and optimized with the serve command #1098

Closed thescientist13 closed 1 year ago

thescientist13 commented 1 year ago

Type of Change

Bug

Summary

After upgrading to v0.28.0, noticed that when introduced API routes into a "static" project, this combination triggers the hybrid server, but the HTML coming back is showing a bunch of 404s because none of the assets were loading correctly in the browser.

Screen Shot 2023-04-15 at 2 25 03 PM

<link rel="stylesheet" href="../styles/main.css" data-gwd-opt="inline">

<script type="module" data-gwd-opt="static" src="../components/footer/footer.js"></script>
<script type="module" data-gwd-opt="static" src="../components/header/header.js"></script>
<script type="module" src="../components/nav/nav.js"></script>
<script type="module" src="../components/video-card/video-card.js"></script>

The reason for this is it looks like all the paths (from a template) were pointing to the development paths and so of course everything is broken as a result.

As a note, seems like these shouldn't be returning a 500 though, should be a 404.

Details

The issue after some debugging appears to be that when an SSR page goes into its optimization phase, none of the imports are there because graph.json is written before all the files are bundled. The simple solution is to just re-serialize graph.json during the bundling phase to get that latest state.

My concern is that these imports are built up from modelResource, which will also have a ton of raw contents, which would significantly bloat graph.json, so should keep that in mind.

Should also make sure this can be tested.