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

Move getStaticPaths call to happen during generation #4047

Merged
merged 5 commits into from
Jul 26, 2022

Conversation

matthewp
Copy link
Contributor

@matthewp matthewp commented Jul 25, 2022

Changes

  • The call to getStaticPaths during the build is moved to the end of the process, during page generation.
  • This prevents us from ever needing to call vite.ssrLoadModule anywhere in the build now. We are 100% completely static.
  • This should improve performance as we are no longer double-building this code.
  • This also fixes a bug with Lit and getStaticPaths. Before this change if you use a Lit element in a page behind getStaticPaths you would get a window is undefined error. This was because getStaticPaths was being called upfront, when the renderer had not yet run, and therefore the shim was not applied. Now it happens as it should.
  • Closes 🐛 BUG: Referencing a lit component within a dynamic route doesnt work #3951

Testing

  • Tests added

Docs

N/A, bug fix.

@changeset-bot
Copy link

changeset-bot bot commented Jul 25, 2022

🦋 Changeset detected

Latest commit: 3d865dc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
astro Patch
@e2e/astro-component Patch
@e2e/error-react-spectrum Patch
@e2e/error-sass Patch
@e2e/errors Patch
@e2e/lit-component Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/svelte-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 25, 2022
const { astroConfig, logging, routeCache, ssr, viteServer } = opts;
if (!viteServer) throw new Error(`vite.createServer() not called!`);
const filePath = new URL(`./${route.component}`, astroConfig.root);
const mod = (await viteServer.ssrLoadModule(fileURLToPath(filePath))) as ComponentInstance;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was the last ssrLoadModule call still happening during the build.

Copy link
Member

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

Nice! I know you've been working towards this for a while. LGTM! If tests are passing, I'll merge this to get it in in time for the nightly release.

@FredKSchott
Copy link
Member

Ah, I'd hoped the breaking test was a small bug but it looks like its due to an actual regression. Probably due to a side-effect of changing the order that you build files in the build command. Reverted my attempt at the small fix, and will leave for you to solve!

@matthewp
Copy link
Contributor Author

Yeah, I think it's because manifest.routes is ordered and that is how we were previously adding paths and this PR changes that. I think I know how to fix it though.

@matthewp matthewp merged commit 453c026 into main Jul 26, 2022
@matthewp matthewp deleted the move-get-static-paths branch July 26, 2022 12:54
@astrobot-houston astrobot-houston mentioned this pull request Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: Referencing a lit component within a dynamic route doesnt work
2 participants