Skip to content
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

fixed errors on /app/articles/app/page.tsx and added types for isomorphic-dompurify #1179

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/(app)/articles/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ArticleAdminPanel from "@/components/ArticleAdminPanel/ArticleAdminPanel"
import { type Metadata } from "next";
import { getPost } from "@/server/lib/posts";
import { getCamelCaseFromLower } from "@/utils/utils";
import { generateHTML } from "@tiptap/html";
import { generateHTML } from "@tiptap/core";
import { TiptapExtensions } from "@/components/editor/editor/extensions";
import DOMPurify from "isomorphic-dompurify";
import type { JSONContent } from "@tiptap/core";
Expand Down Expand Up @@ -119,11 +119,15 @@ const ArticlePage = async ({ params }: Props) => {

{isTiptapContent ? (
<div
dangerouslySetInnerHTML={{ __html: renderedContent }}
dangerouslySetInnerHTML={{ __html: renderedContent ?? "" }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we fallback to "" should we not have an error thrown?

Copy link
Contributor Author

@petercr petercr Oct 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So without the extra || "" you get a Typescript error warning you that if it ends up getting passes a null value, there will be problems.

It seems like an easy fix, but if you wanted to default to something else I will be happy to change it 👍🏻

Or if you want me to pass in or throw a new error I could add that too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if there is no content it should probably be notFound since there is no data (or content) for that page? That make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great I will just bring in the NotFound component then, and replace the empty string instance with that 👍

className="tiptap-content"
/>
) : (
<div>{renderedContent}</div>
<div>
{Markdoc.renderers.react(renderedContent, React, {
components: markdocComponents,
})}
</div>
)}
</article>
{post.tags.length > 0 && (
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"@svgr/webpack": "^8.1.0",
"@tailwindcss/typography": "^0.5.13",
"@types/chance": "^1.1.6",
"@types/dompurify": "^3.0.5",
"@types/node": "^22.7.5",
"@types/nodemailer": "^6.4.15",
"@types/pg": "^8.11.5",
Expand Down
Loading