Skip to content

AppData.getArray() can return null, expected empty array #191

Description

@andreas-andersson

What, where

When using a page-list component and leaving it empty the return value is sometimes null, not as expexted an emtpy Node[].

From the AppData interface it should always be an array of Nodes.

export interface AppData {
  get(...key: string[]): unknown;
  getNode(key: string): Node;
  getArray(key: string): Node[];
  getNumber(key: string): number;
}

Example

config/index.html

      <input
        type="hidden"
        data-types="sv:archive"
        data-component="page-list"
        name="articlePathNodes"
        id="articlePathNodes"
        data-sortable
      />
...
let articlePathNodes = appData.getArray("articlePathNodes") as Node[];
articlePathNodes = articlePathNodes.filter((node: Node) => nodeTypeUtil.isArchive(node));
...

The resulting error is only visible on the addon preview.

EcmaError: TypeError: Cannot call method "filter" of null (<sitevision>#1890)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions