Replies: 1 comment 2 replies
-
It wouldn't really change anything. Static imports have to be hoisted anyways. If it's a dynamic import, it doesn't have to be hoisted (but if you want it to only run once, put it in the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been putting imports in <script> but today I needed to run a line of code once after the import, and not each time the component renders (since the library makes the config option readonly after setting it once), so I had to move the import into <script module> with the line of code after it.
And it got me thinking, where should imports really go, in <script> or <script module>? I'm guessing svelte is just hoisting all the imports up to the top level anyway, since it wouldn't make sense to import them each time the component executes what is in <script>, but does that possible cause confusion?
Would enforcing imports go into <script module> make more sense and display a warning if imports are in <script> ?
Beta Was this translation helpful? Give feedback.
All reactions