-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: disallow calling getContext
inside element
#7864
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
Conversation
I think CI is actually failed. |
oh okay i'll take a look at it 🙈 |
getContext
inside element
marked this as v4 because strictly speaking it's a breaking change |
@dummdidumm is attempting to deploy a commit to the Svelte Team on Vercel. A member of the Team first needs to authorize it. |
@tanhauhau if you get a chance, it looks like the tests will need to be updated on this one |
Wondering if we should just leave it be and not do this explicitly, instead stating in the docs that using |
If we added the check now, I don't think we'd be obligated to keep if for Svelte 5. For Svelte 4, it seems a bit safer than a warning the docs that people may or may not see. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR breaks {#await}
block.
<script>
let promise = Promise.resolve();
</script>
{#await promise}
<p>waiting...</p>
{:then value}
<p>then!</p>
{/await}
To fix this, I think we need variables scope analyzer and throw compile error if get_context
is used in the template block.
But handling this by Svelte compiler is a bit difficult because we don't have a scope analyzer.
So to do this, an easier way is that we will implement this in ESLint plugin.
What do you think?
Given that it looks to be really tricky to get this working properly I'm giving this the "one day" label. I think a note in the docs that you shouldn't use Svelte functions in the template would be enough. |
Closing since we ended up going in the opposite direction: #11061 |
Fixes #7549
Throwing error when using
getContext
inside element, eg: attribute, text content, ...Before submitting the PR, please make sure you do the following
[feat]
,[fix]
,[chore]
, or[docs]
.Tests
npm test
and lint the project withnpm run lint