Skip to content

getResourceFromContext returns null when using sparse fieldset for resource type #155

Open
@shadcn

Description

@shadcn
const node = await getResourceFromContext("node--article", {
  params: {
    "fields[node--article]": "title"
  }
})

The code above (on a Drupal site with translation enabled) will return null because of the bug here:

// If no locale is passed, skip entity if not default_langcode.
// This happens because decoupled_router will still translate the path
// to a resource.
// TODO: Figure out if we want this behavior.
// For now this causes a bug where a non-i18n sites builds (ISR) pages for
// localized pages.
if (!context.locale && !resource?.default_langcode) {
return null
}

Solution: Always include default_langcode for the resource (until this is resolved in decoupled_router).

const node = await getResourceFromContext("node--article", {
  params: {
    "fields[node--article]": "title,default_langcode"
  }
})

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions