Skip to content

Commit

Permalink
fix: add missing optional chaining operator to next recipe
Browse files Browse the repository at this point in the history
## Description

Add missing `?.` optional chaining operator in `export async function
generateMetadata` in `recipes/next/app/[...puckPath]/page.tsx`.

## Error:
```
next-recipe:dev:  ⨯ app/[...puckPath]/page.tsx (31:25) @ root
next-recipe:dev:  ⨯ TypeError: Cannot read properties of undefined (reading 'root')
next-recipe:dev:     at Module.generateMetadata (./app/[...puckPath]/page.tsx:32:29)
next-recipe:dev: digest: "1676022290"
next-recipe:dev:   29 | 
next-recipe:dev:   30 |   return {
next-recipe:dev: > 31 |     title: getPage(path).root.title,
next-recipe:dev:      |                         ^
next-recipe:dev:   32 |   };
next-recipe:dev:   33 | }
next-recipe:dev:   34 |
```

## Why this happens:

By default the browser attempts to load the
`http://localhost:3000/favicon.ico` file but because this file does not
exist as a static file, `next.js` server attempts to handle the request
using `/app/[...puckPath]/page.tsx` route and because `favicon.ico` path
is not defined in `/database.json` this error occurs.

## Steps to reproduce:
### Option 1.
#### Clone this repo
```bash
git clone [email protected]:measuredco/puck.git
cd puck
```

#### Start dev
```bash
yarn dev --scope next-recipe --no-deps
```

### Option 2.
#### Create new project using `next` recipe
```bash
npx create-puck-app my-app
cd my-app
```

#### Start dev
```bash
yarn dev
```

### Open puck editor
```
Browser navigate to -> http://localhost:3000/edit
```

## Commit that introduced this error

34f248c#diff-03f6d84aea18b78020e4edaabac75a948a5c6b56b5212194570e0364684f3f41R31

## Environment
```
$ uname -a
Linux *** 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
$ node -v
v18.17.1
$ yarn -v
1.22.19
$ git rev-parse HEAD
e4cab76

Browser:
Microsoft Edge
Version 117.0.2045.43 (Official build) (64-bit)

```
  • Loading branch information
soudasuwa authored Oct 3, 2023
1 parent f4b0563 commit a368319
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function generateMetadata({
}

return {
title: getPage(path).root.title,
title: getPage(path)?.root.title,
};
}

Expand Down
2 changes: 1 addition & 1 deletion recipes/next/app/[...puckPath]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function generateMetadata({
}

return {
title: getPage(path).root.title,
title: getPage(path)?.root.title,
};
}

Expand Down

0 comments on commit a368319

Please sign in to comment.