Skip to content

t.at is not a function being thrown in production only #3644

@spencercorwin

Description

@spencercorwin

Marked version:
15.0.7

Describe the bug
I'm getting error reports from my client application in production with the error message "t.at is not a function. Please report this to https://github.com/markedjs/marked". This is bundled and minified production code so I'm having trouble pinning down exactly where in the marked source this coming from.

It appears to only happen when my blog is visited by web crawlers. I don't see any issues when I visit the blog myself in prod or locally.

To Reproduce
I can't reproduce it so far. I upgraded from 14.1.3 to 15.0.7 and started getting these errors in prod. You can visit the blog where each blog post is just markdown rendered on the client at https://microgreenmanager.com/blog.

Here is the code where I use marked:

import { type RendererObject, marked } from 'marked';
import * as React from 'react';
import { Root } from './Markdown';

interface Props {
  readonly source: string;
  readonly 'data-test'?: string;
}
export default function RenderMarkdown({ 'data-test': dataTest, source }: Props) {
  const renderer: RendererObject = {
    link({ href, text, title }): string {
      // If the link is for YouTube, then return a YouTube embed
      if (href.startsWith('https://www.youtube.com/watch?v=')) {
        const videoId = href.split('=')[1];
        const iframeStyles = 'position:absolute;top:0;left:0;width:100%;height:100%;';
        const wrapperStyles = 'position:relative;overflow:hidden;width:100%;padding-top:56.25%;';
        return `
          <div id="youtube-embed" style="${wrapperStyles}">
            <iframe
              style="${iframeStyles}"
              src="https://www.youtube.com/embed/${videoId}"
              title="${text}"
              frameborder="0"
              allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
              allowfullscreen
            ></iframe>
          </div>
        `;
      }
      return `<a href="${href}" ${title ? `title="${title}"` : ''} target="_blank" rel="noopener noreferrer">${text}</a>`;
    },
  };
  marked.use({ renderer });
  // biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>
  return <Root data-test={dataTest} dangerouslySetInnerHTML={{ __html: marked.parse(source, { async: false }) }} />;
}

Expected behavior
No errors being thrown.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions