pablo-abc / svelte-markdown

Markdown parser to svelte components
MIT License
358 stars 50 forks source link

The "suppressWarnings" function breaks the console.warn function across entire Svelte UI #94

Open glenatron opened 3 months ago

glenatron commented 3 months ago

A small but irritating error here - if I call console.warn({"abc": "def"}) anywhere in my Svelte app after I have opened a view that uses SvelteMarkdown I get the following error message:

Uncaught TypeError: message.includes is not a function
    warn supress-warnings.js:7

The cause is the following code from supress-warnings.js:

import { onMount } from 'svelte'

export function supressWarnings() {
  const origWarn = console.warn

  console.warn = (message) => {
    if (message.includes('unknown prop')) return
    if (message.includes('unexpected slot')) return
    origWarn(message)
  }

  onMount(() => {
    console.warn = origWarn
  })
}

As you might imagine, the includes property doesn't exist on arbitrary objects so it fails there - a simple message.hasOwnProperty("includes") check would fix this.

It does look as though the supressWarnings function should only be active until onMount completes, so I wonder if there's something else going on here, but at the very least that would prevent it from breaking things worse when a warning is raised.