-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Module-level binding in svelte 3.16 #4086
Comments
@rootasjey What did you upgrade from? What's the latest version that works? Is it possible to create a REPL to demonstrate the issue? |
The root of the matter seems to be: <script context='module'>
let foo;
</script>
<div bind:this={foo}/> I haven't checked whether this did the right thing in 3.15.0. It's somewhat weird having a binding to a module-level variable (I guess all of the instances of the component would just overwrite one another?) |
@Conduitry, 3.15.0 compiles OK, at least according to REPL. |
I see that it compiles okay - what I haven't checked is whether the code does the right thing. |
Yeah I thought I was doing something not-classy when writing this (the module-level binding). Thanks! |
svelte component script natively is module, why use syntax: "<script context="module">" ? I am a fresh man, Am I misunderstood svelte official tutorial? |
In 3.15, it has the last in behavior you'd expect (though probably not a good thing)... every button in the repl below prints "Third". https://svelte.dev/repl/623d6db3ad1242208a191c5ac1a411fc?version=3.15.0 The invalidate routine is much simpler in 3.15 than 3.16.5... for all the tests in the routine, we still miss
|
Maybe I don't understand the use case here, but shouldn't this just be a store instead of a module level variable? |
I think the broader problem here is that we shouldn't try to generate invalidation code for any module-level variables (unless we're updating it as a store). This: diff --git a/src/compiler/compile/render_dom/Renderer.ts b/src/compiler/compile/render_dom/Renderer.ts
index 046a90b68..be9e700a0 100644
--- a/src/compiler/compile/render_dom/Renderer.ts
+++ b/src/compiler/compile/render_dom/Renderer.ts
@@ -160,6 +160,10 @@ export default class Renderer {
return x`${name.slice(1)}.set(${value || name})`;
}
+ if (variable && variable.module) {
+ return value;
+ }
+
if (
variable &&
!variable.referenced && seems to generate sensible code from my example component above, and doesn't break any existing tests. |
Additionally, we probably shouldn't be checking the dirty bitmask for changes to module-level variables, nor should these variables even be given a bit in the bitmask, but I don't have quick fixes for those yet. |
Binding to a module-level variable no longer causes a compiler error in 3.18.2. |
Hi, after I updated svelte to the version
3.16.0
, the build command doesn't work anymore.Modules versions:
"svelte": "3.16.0"
"rollup-plugin-svelte": "5.1.1",
Output:
What's in the file:
Header.svelte
To see the full code you can go to my repo Header.svelte
The same code works with the svelte version
3.15.0
The bug appears when I require the exported functions in the
script module
with svelte3.16.0
.Example:
The text was updated successfully, but these errors were encountered: