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

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

Open
glenatron opened this issue Aug 13, 2024 · 0 comments

Comments

@glenatron
Copy link

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.

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

No branches or pull requests

1 participant