Skip to content

A map object in collection entry created by Object Loader is broken #13849

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

Open
1 task
yukitomoda opened this issue May 24, 2025 · 0 comments
Open
1 task

A map object in collection entry created by Object Loader is broken #13849

yukitomoda opened this issue May 24, 2025 · 0 comments
Labels
needs triage Issue needs to be triaged

Comments

@yukitomoda
Copy link

Astro Info

yt@yt:~/tmp/loader-api-and-map$ npm run astro info

> [email protected] astro
> astro info

Astro                    v5.8.0
Node                     v22.11.0
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

A map object in collection entry created by Object Loader API
is broken after I getEntry it.

Specifically, the map object cannot be used with its method (e.g. entry.data.map.entries() throws an Error) and appears its all key-values are lost.

My definition of content collection and code using the entry below (src/content/config.ts, src/pages/index.astro). :

import { z, defineCollection } from "astro:content";

export const testCollection = defineCollection({
  loader() {
    // Simply returning a value with Map object.
    return [
      {
        id: 'id',
        map: new Map<string, string>([
          ['foo', 'bar'],
          ['hoge', 'fuga']
        ])
      }
    ]
  },
  schema: z.object({
    map: z.map(z.string(), z.string()),
  })
})

export const collections = {
  'test': testCollection,
};
---
import { getEntry } from "astro:content";

const entry = await getEntry("test", "id");
const pairs = entry?.data.map.entries();
// An error occurred above
// > Method Map.prototype.entries called on incompatible receiver #<Map>
---

<html lang="en">
	<head>
		<meta charset="utf-8" />
		<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
		<meta name="viewport" content="width=device-width" />
		<meta name="generator" content={Astro.generator} />
		<title>Astro</title>
	</head>
	<body> </body>
</html>

What's the expected result?

The map's data are available and it's methods can be called in page.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-ppjyehzr?file=src%2Fpages%2Findex.astro

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 May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant