perf: inline default imports into template#13242
Conversation
🦋 Changeset detectedLatest commit: 84d1cfb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
61b700b to
84d1cfb
Compare
| } | ||
| } | ||
| return has_expression_tag; | ||
| return { need_to_escape }; |
There was a problem hiding this comment.
Really not a fan of a function returning false | { need_to_escape: boolean } — it's a messy and confusing type. If a function name begins with is_ then it ought to return a boolean; if it needs to return more granular information than that then something like analyze_expression would probably be better
|
Technically this is unsafe. There's nothing special about default imports that makes them non-live, it's purely about the way that they're conventionally exported. When you do something like this... export default foo;...you're effectively declaring a hidden variable and exporting that as the default: const __default = foo;
export { __default as default };Since export { foo as default };The consequence is that when you see |
|
hmm. yeah. I'm glad we have your arcane knowledge of JS because I had no idea that was a thing I'll try to solve this on the Vite side then: vitejs/vite#18119 |
|
Realised we couldn't do this even if we didn't have to worry about live bindings — this button won't be enabled on hydration, because the <script>
import server from './is-server.js';
</script>
<button disabled={server}>
{server ? "can't click me yet" : 'click me!'}
</button>The text is updated, but you still can't click the button. |
#13075 reduced the size of the compiled output on my site quite a lot. However, there are still hundreds of lines (~8kb) of output remaining created as the result of referencing a pair of imported SVGs that can be removed from my site by also inlining imports with this PR