There were a number of things wrong or could have been improved with the [Draft Preview Example](https://github.com/payloadcms/payload/tree/main/examples/draft-preview), namely: - The package.json was missing `"type": "modue"` which would throw ESM related import errors on startup - The preview secret was missing entirely, with pointless logic was written to throw an error if it missing in the search params as opposed to not matching the environment secret - The `/next/exit-preview` route was duplicated twice - The preview endpoint was unnecessarily querying the database for a matching document as opposed to letting the underlying page itself 404 as needed, and it was also throwing an inaccurate error message Some less critical changes were: - The page query was missing the `depth` and `limit` parameters which is best practice to optimize performance - The logic to format search params in the preview URL was unnecessarily complex - Utilities like `generatePreviewPath` and `getGlobals` were unnecessarily obfuscating simple functions - The `/preview` and `/exit-preview` routes were unecessarily nested within a `/next` page segment - Payload types weren't aliased
211 B
211 B