-
-
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
feat: skip static nodes #12914
feat: skip static nodes #12914
Conversation
🦋 Changeset detectedLatest commit: 19db5e6 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 |
packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js
Outdated
Show resolved
Hide resolved
if (within_bound_contenteditable || !has_state) { | ||
state.init.push(b.stmt(b.assignment('=', b.member(id, 'nodeValue'), value))); | ||
} | ||
} else { | ||
const update = b.stmt(b.call('$.set_text', id, value)); | ||
|
||
expression = (is_text) => b.call('$.sibling', id, is_text && b.true); | ||
if (has_call && !within_bound_contenteditable) { | ||
state.init.push(build_update(update)); | ||
} else if (has_state && !within_bound_contenteditable) { | ||
state.update.push(update); | ||
} | ||
} |
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.
This can be simplified to
if (within_bound_contenteditable || !has_state) { | |
state.init.push(b.stmt(b.assignment('=', b.member(id, 'nodeValue'), value))); | |
} | |
} else { | |
const update = b.stmt(b.call('$.set_text', id, value)); | |
expression = (is_text) => b.call('$.sibling', id, is_text && b.true); | |
if (has_call && !within_bound_contenteditable) { | |
state.init.push(build_update(update)); | |
} else if (has_state && !within_bound_contenteditable) { | |
state.update.push(update); | |
} | |
} | |
if (within_bound_contenteditable || !has_state) { | |
state.init.push(b.stmt(b.assignment('=', b.member(id, 'nodeValue'), value))); | |
} else if (!within_bound_contenteditable) { | |
const update = b.stmt(b.call('$.set_text', id, value)); | |
if (has_call) { | |
state.init.push(build_update(update)); | |
} else if (has_state) { | |
state.update.push(update); | |
} | |
} |
... which shows that there's now the possibility to not add anything to init or update at all - previously it always did. Is that a bug?
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.
huh, whoops — just wanted to avoid creating update
unnecessarily. reverted this drive-by change.
i notice that if we remove the contenteditable stuff altogether no tests fail, which seems weird. making a mental note to look into this
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.
Maybe @trueadm knows more, IIRC he worked on content editable a while back
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.
None of the contentEditable stuff is very testable unfortunately. JSDOM has no support for it and Playwright support is flaky (from experience using it with Lexical).
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.
ah, i see. we should probably add a snapshot test in that case. will make a note
packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js
Show resolved
Hide resolved
} | ||
|
||
prev = () => id; | ||
skipped = 1; |
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.
why 1? Could use an explanatory comment
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.
yeah, this code makes me itch. i spent an unreasonable amount of time trying to make is 0
instead and remove the skipped -= 1
below, but couldn't quite make things behave. it's a new day so will take another run at it
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.
ok i gave up — the cure would be worse than the disease. settled for adding comments instead
flush_sequence(sequence); | ||
} | ||
|
||
if (skipped > 1) { | ||
skipped -= 1; |
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.
why -= 1? Could use an explanatory comment (I suspect it's connected to the skipped = 1
thing above)
…s/shared/fragment.js Co-authored-by: Simon H <[email protected]>
follow-up to #12849. implements #12855 (comment).
Basically, given some code like this...
...we can skip over all the static stuff between
{before}
and{after}
:It's a little messy, hence draft status, but you get the idea. It should result in a decent reduction in generated code size for mdsvex files etc.
Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint