-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Consider imports that are not updated or mutated to be constant #8933
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
Comments
Hmm. Thinking about this a bit more... In the case of handling images it's not actually |
I realized we wouldn't have to create a new comment like And probably we wouldn't actually inline the constants , but just do string interpolation. I.e. convert it to:
|
I'm thinking a good way to implement this actually would be to have a new compiler option that accepts a regex for determining whether an import is an asset and thus immutable. Then |
Describe the problem
This gets converted to 50 lines of JS:
And it scales really well. If you put 5 pictures inside a
<div>
you end up with 50 lines of JS. I believe the concise output here is courtesy of #7426 in Svelte 4.0.On the other hand, this gets converted to 112 lines of JS:
And it doesn't scale nearly as nicely. If you put just 2 pictures inside a
<div>
you end up with 176 lines of JS. But if we want to use things like Vite's asset handling, we have to write code that looks a lot more like the second.This ends up being important if we implement the Svelte image tag as a preprocessor as @Rich-Harris has proposed (sveltejs/kit#9787 (comment)). The preprocessor approach doesn't scale as well as an
Image
component at the moment, but I believe it'd do even better if we made this change.Describe the proposed solution
I'm hoping it'd be easy at least with the constant primitives. With the constant object you might have to do a bit more work to see that nothing's touching it. If it helps analyze it, we could create those objects wrapped in
Object.freeze
or something to indicate that they're not modified.Alternatives considered
Don't get that final point on Lighthouse 😆
Importance
nice to have
The text was updated successfully, but these errors were encountered: