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

Empty content collections with programmatic API since 5.0.3 #12652

Closed
1 task
HiDeoo opened this issue Dec 5, 2024 · 3 comments · Fixed by #12947
Closed
1 task

Empty content collections with programmatic API since 5.0.3 #12652

HiDeoo opened this issue Dec 5, 2024 · 3 comments · Fixed by #12947
Assignees
Labels
- P2: has workaround Bug, but has workaround (priority) feat: content layer Related to the Content Layer feature (scope)

Comments

@HiDeoo
Copy link
Member

HiDeoo commented Dec 5, 2024

Astro Info

Astro                    v5.0.3
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Spotted in a similar scenario in an E2E test in the Starlight repo, it looks like using the Astro programmatic API to build a project using content collections, serving it and then starting a dev server leads to different results:

  • The served production build works as expected.
  • The dev server logs that the collection does not exist or is empty.

In the linked repro, the following script is immediately run:

import { dev, build, preview } from 'astro';

const root = './';

await build({ logLevel: 'debug', root });
const prodServer = await preview({ logLevel: 'debug', root });

const devServer = await dev({ root });

The preview panel will work as expected as it's showing the production version built first and served on the port 4321.
Manually changing the URL to switch to the dev server (there is a 4321 in the URL that can be changed to 4322) will show a 404 error and log the mentioned error.

Note that this works fine when using Astro v5.0.2, maybe related to #12640 but only a guess.

What's the expected result?

The expected result is the same behavior in both cases.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-gaqwbs?file=repro.js&on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.
@lilnasy
Copy link
Contributor

lilnasy commented Dec 5, 2024

Ran into this as well.

@lilnasy
Copy link
Contributor

lilnasy commented Dec 5, 2024

isDev ??= process?.env.NODE_ENV === 'development';

NODE_ENV can be testing during dev.

A quick fix would be to be explicit here as well (similar to the changes to dev() in #12640):

const cacheFile = getDataStoreFile(this.#settings);

A better fix would be derive isDev from createVite's command to remove the guesswork altogether:

export async function createVite(
commandConfig: vite.InlineConfig,
{ settings, logger, mode, command, fs = nodeFs, sync, manifest, ssrManifest }: CreateViteOptions,
): Promise<vite.InlineConfig> {

lilnasy added a commit to lilnasy/gratelets that referenced this issue Dec 9, 2024
* test with latest versions

* adjust test: adds-to-head

* adjust test: dynamic-import

* fix script command

* adjust tests: prerender-patterns

* adjust tests: scope

* fix(typed-api): declaration file generation

* update test script for emotion

* update dependencies

* update dev dependency to avoid type error

* astro 5 replaces hybrid option with static

* new fields in APIContext

* updated lockfile

* remain on typescript 5.6

* fix getting scope from compiler

* adjust test: adds-to-head

* workaround for astro bug

* remove console.log

* fix(emotion): css on server components since vite 6

* chore(global): directly augment types

* fix(scope): use final astro config for the compiler

* chore(scope): directly augment types

* chore(dynamic import): directly augment types

* chore(emotion): directly augment types

* chore(typed-api): rework type generation

* update astro to 5.0.3

* switch workaround for withastro/astro#12612 with workaround for withastro/astro#12652

* feat(emotion): caching

* chore(client-interaction): minor bump

* chore(dynamic-import): major bump

* chore(typed-api): minor bump

* chore(astro-emotion): major bump

* chore(astro-global): major bump

* chore(astro-scope): major bump

* update lockfile

* remove console.log
@delucis
Copy link
Member

delucis commented Jan 9, 2025

Noting that @ascorbic hoped this might be a duplicate of #12866 and fixed in 5.1.4, but it unfortunately doesn’t seem to be the case. Starlight end-to-end tests which are impacted by this issue are still failing in withastro/starlight#2736 after to updating to 5.1.4

@ascorbic ascorbic added the feat: content layer Related to the Content Layer feature (scope) label Jan 9, 2025
@ascorbic ascorbic self-assigned this Jan 9, 2025
@ascorbic ascorbic added - P3: minor bug An edge case that only affects very specific usage (priority) - P2: has workaround Bug, but has workaround (priority) and removed needs triage Issue needs to be triaged - P3: minor bug An edge case that only affects very specific usage (priority) labels Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) feat: content layer Related to the Content Layer feature (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants