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

Warn the user to use {@render} instead of {} with snippets #2547

Open
RaphGL opened this issue Oct 27, 2024 · 0 comments
Open

Warn the user to use {@render} instead of {} with snippets #2547

RaphGL opened this issue Oct 27, 2024 · 0 comments
Labels
feature request New feature or request

Comments

@RaphGL
Copy link

RaphGL commented Oct 27, 2024

Description

When using a snippet to "render" it to the DOM, you have to use {@render snippetname()} but simply using {snippetname} is valid svelte code and is not rejected by the compiler, this results in a bunch of javascript text instead of what the user actually wants (render the actual content).

Proposed solution

When there's type information available, check for if an identifier is a Snippet then upon asserting that it in fact is a snippet then warn the user and ask for them to instead use {@render <snippetName>()}

If the javascript output is intended (???), some sort of directive could be used to disable the warning for that instance. Not sure if this exists in the svelte LSP.

Alternatives

No response

Additional Information, eg. Screenshots

{#snippet something()}
  <p>hello</p>
{/snippet}

 <!-- the compiler is happy to render it without caring about whether it's a snippet or not -->
<div>{something}</div>

<!-- works as intended -->
<div>{@render something()}</div> 
@dummdidumm dummdidumm added the feature request New feature or request label Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants