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

Injected Routes are not being pre-rendered in hybrid mode. #7721

Closed
1 task
tgerstle opened this issue Jul 19, 2023 · 16 comments
Closed
1 task

Injected Routes are not being pre-rendered in hybrid mode. #7721

tgerstle opened this issue Jul 19, 2023 · 16 comments
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: ssr Related to SSR (scope)

Comments

@tgerstle
Copy link

What version of astro are you using?

2.8.5

Are you using an SSR adapter? If so, which one?

Node

What package manager are you using?

npm

What operating system are you using?

Mac

What browser are you using?

Chrome

Describe the Bug

When output is set to hybrid and routes are injected using an adapter, the injected routes are not pre-rendered. The routes are pre-rendered if no output is set. If the output is set to server and export const prerender = true is set in the frontmatter, the route still is not prerendered.

What's the expected result?

I expect injected routes to pre-render by default in hybrid mode. An alternative could be to ensure the front matter "prerender" variable works normally on injected routes or perhaps add a configuration on the injected routes.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/astro-ccvkpy?file=astro.config.mjs

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jul 19, 2023
@natemoo-re
Copy link
Member

I believe injectRoute({ entryPoint: "value", prerender: true }) should work. I don't see this in the docs, though! We'll need to update that.

@natemoo-re natemoo-re added needs response Issue needs response from OP and removed needs triage Issue needs to be triaged labels Jul 19, 2023
@tgerstle
Copy link
Author

tgerstle commented Jul 19, 2023 via email

@natemoo-re
Copy link
Member

Hmm, odd. When using entryPoint: './src/site/demo/index.astro', I am seeing the behavior you mentioned. But when using entryPoint: 'src/site/demo/index.astro', all the metadata seems correct and the page is prerendered. Seems like a bug on our end!

@natemoo-re natemoo-re added - P4: important Violate documented behavior or significantly impacts performance (priority) and removed needs response Issue needs response from OP labels Jul 19, 2023
@natemoo-re
Copy link
Member

Some more context from @delucis here on a similar issue. #7642 (comment)

This seems like a poor API design choice on our end, I would expect both formats to work in this case.

@delucis
Copy link
Member

delucis commented Jul 19, 2023

I'm surprised entryPoint: 'src/site/demo/index.astro' works at all! In my testing it didn't previously (which kind of makes sense, because we support resolving an npm module here, so src should be the src npm package).

@Princesseuh Princesseuh added the feat: ssr Related to SSR (scope) label Jul 20, 2023
@natemoo-re
Copy link
Member

Still seeing an issue with entryPoint: './src/site/demo/index.astro' after all the recent fixes, so keeping this open.

@rishi-raj-jain
Copy link
Contributor

rishi-raj-jain commented Sep 23, 2023

Is this still an issue with Astro 3?

Also, ./src/ is expected to work and src/ shouldn't be used anymore, correct?

@lilnasy
Copy link
Contributor

lilnasy commented Nov 7, 2023

The bugs themselves are fixed but a test could be added before this issue closes.

@Fryuni
Copy link
Member

Fryuni commented Dec 8, 2023

This issue is still happening for .ts routes on Astro 4

.astro routes are being prerendered fine, even mixing prerendered and SSR routes are working, but this only gets prerendered with output: 'static':

injectRoute({
  pattern: '/[...path]',
  entrypoint: 'mypackage/route.ts',
  prerender: true,
});

This works:

injectRoute({
  pattern: '/[...path]',
  entrypoint: 'mypackage/route.astro',
  prerender: true,
});

@natemoo-re
Copy link
Member

Sorry for the lack of updates here! Confirming that this is definitely still an issue. I'll make sure this gets back on our TODO list.

@nadar
Copy link

nadar commented Jan 5, 2024

@natemoo-re @Fryuni, I am far from being an astro expert (but we like it so far! 😄), yet we are trying to create integrations that can be distributed via npm (obviously). We have noticed that when we use injectRoute() in the astro:config:setup hook, there is no way to provide an endpoint file through an NPM package that will be correctly resolved into the node_modules folder. Even though the docs state that we should use @npmpackage/.../foobar.ts (at least in the middleware section => https://docs.astro.build/en/reference/integrations-reference/#addmiddleware-option), it does not resolve correctly. So we tested all those cases, and nothing works:

injectRoute({
  pattern: '/sitemap.xml',
  entrypoint: '@flyo/nitro-astro/sitemap.js'
})
injectRoute({
  pattern: '/sitemap.xml',
  entrypoint: 'sitemap.js'
})
injectRoute({
  pattern: '/sitemap.xml',
  entrypoint: './sitemap.js'
})

We tested with both .ts and .js files, but neither works.

No matter what, the above injectRoute results in the following error when using the integration in a project: 07:58:43 [ERROR] ENOENT: no such file or directory, open '/root/projects/sites/mysuperduperproject.com/@flyo/nitro-astro/sitemap.js'

Here is the full integration: https://github.com/flyocloud/nitro-astro/blob/main/index.ts#L60-L63

Does this issue confirm my bug, or is it something different and I should create a new issue?

@Fryuni
Copy link
Member

Fryuni commented Jan 5, 2024

@nadar

  • The pattern should not start with /, it is already anchored to the start. Look at how Starlight does it.

  • The entrypoint is an import path, not a file path. I think the one in your first snippet should work since ESM imports should resolve to the file when it is explicit. Test changing just the pattern.

    If changing just the pattern doesn't work, try explicitly exporting them from your package
    This is how Starlight does that for reference.
    So you can try adding "./sitemap": "./sitemap.js" here and use this:

    injectRoute({
      pattern: 'sitemap.xml',
      entrypoint: '@flyo/nitro-astro/sitemap'
    });

@nadar
Copy link

nadar commented Jan 5, 2024

Thank you so much @Fryuni it works! Should i send a PR for improve the documentations? So everyone struggling on this could profit from your generous answer.

  1. i have added "./sitemap.js": "./sitemap.js" to export defintion of package.json
  2. defined the entrypoint as followed entrypoint: '@flyo/nitro-astro/sitemap.js'

@Fryuni
Copy link
Member

Fryuni commented Jan 6, 2024

Should i send a PR for improve the documentations?

If you have an idea for an improvement I think it will be welcomed. Be sure to check the docs contributing guide if it is your first time.

@ematipico
Copy link
Member

I will look into this issue.

@ematipico
Copy link
Member

Closing the issue. I tested the reproduction with the latest Astro, and both injected routes are correctly pre-rendered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: ssr Related to SSR (scope)
Projects
None yet
Development

No branches or pull requests

9 participants