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

Fix/check content type #1754

Merged
merged 3 commits into from
Nov 9, 2021
Merged

Conversation

togami2864
Copy link
Contributor

@togami2864 togami2864 commented Nov 6, 2021

Changes

resolve #1753
I added type guard to avoid TypeError when describing Markdown component with no children.

Testing

I added the test case about this.

Docs

bug fix only

@changeset-bot
Copy link

changeset-bot bot commented Nov 6, 2021

⚠️ No Changeset found

Latest commit: 8b6d73d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -20,7 +20,7 @@ const { privateRenderMarkdownDoNotUse: renderMarkdown } = (Astro as any);
if (!content) {
const { privateRenderSlotDoNotUse: renderSlot } = (Astro as any);
content = await renderSlot('default');
if (content.trim().length > 0) {
if (content !== undefined && content !== null) {
Copy link
Member

Choose a reason for hiding this comment

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

This makes sense to me. Obviously we’d need to test this, but I can see the logic in just assuming strings are correct, and handling non-strings like you’re doing here.

Copy link
Member

@drwpow drwpow left a comment

Choose a reason for hiding this comment

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

This is looking good so far! Happy to review when this isn’t a draft PR.

it("doesn't occurs TypeError when no elements", async () => {
const html = await fixture.readFile('/no-elements/index.html');
// render html without error
expect(!!html).to.equal(true);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
expect(!!html).to.equal(true);
expect(html).to.be.ok;

Same test; just a little easier to read.

@togami2864 togami2864 marked this pull request as ready for review November 9, 2021 04:47
@togami2864 togami2864 requested a review from a team as a code owner November 9, 2021 04:47
@natemoo-re natemoo-re merged commit 7acf762 into withastro:main Nov 9, 2021
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* test: add test case

* fix: add type guard insted of content.trim().length > 0

* test: fix test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: Markdown Component with no children occurs TypeError
3 participants