Skip to content
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

fix: use wholeText for only contenteditable for set_data #8394

Merged
merged 16 commits into from
Mar 21, 2023
Merged

fix: use wholeText for only contenteditable for set_data #8394

merged 16 commits into from
Mar 21, 2023

Conversation

baseballyama
Copy link
Member

@baseballyama baseballyama commented Mar 18, 2023

fix: #5931
close: #5940

I implemented compiler level check instead of runtime check.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with npm test and lint the project with npm run lint

@vercel
Copy link

vercel bot commented Mar 18, 2023

@baseballyama is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me! I'm wondering if we should split this up into two separate methods instead of having one do both

@baseballyama
Copy link
Member Author

Makes sense to me! I'm wondering if we should split this up into two separate methods instead of having one do both

Oh yeah! Then we can reduce runtime level if statement. I will update it.

@baseballyama baseballyama requested a review from dummdidumm March 18, 2023 15:49
);

if (this.has_dynamic_attribute) {
block.chunks.update.push(b`
${fn}(${this.var}, ${data} = @get_spread_update(${levels}, [
block.chunks.update.unshift(b`
Copy link
Member

@dummdidumm dummdidumm Mar 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to switch to unshift here and above? I switched it back to push and the tests all passed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, test case component-event-handler-contenteditable3, get_spread_update is added at ElementWrapper class, and set_data_maybe_contenteditable is added at MustacheTag class.
And MustacheTag is executed earlier than ElementWrapper.

If get_spread_update runs after set_data_maybe_contenteditable, set_data_maybe_contenteditable runs using div_data that is before updating.

To avoid this situation, I use unshift.
I think there are other ways to solve this issue, but I think this is reasonable and anyway, we will dynamically change the compiler in Svelte4, so we don't need to be particular about this.

set_attributes$(div$, div_data$ = get_spread_update$(div$_levels$, [dirty & /*spread*/ 2 && /*spread*/ ctx[1]]));
if (dirty & /*text*/ 1) set_data_maybe_contenteditable$(t$, /*text*/ ctx[0], div_data$['contenteditable']);

@dummdidumm dummdidumm added this to the 3.x milestone Mar 20, 2023
@baseballyama
Copy link
Member Author

I checked the latest code.
For example test casecomponent-event-handler-contenteditable2 uses set_data_maybe_contenteditable, but 3rd params is "true", so this is obviously contenteditable, so in terms of optimization, in this case we can add a function called set_data_contenteditable.
This is the reason why I added contenteditable_truthy_values in the shared directory.

if (dirty & /*text*/ 1) set_data_maybe_contenteditable$(t$, /*text*/ ctx[0], "true");

@baseballyama
Copy link
Member Author

This is just a memo but jsdom doesn't support contenteditable.
So if someone wants to add a test, maybe you need to add a puppeteer test.

- remove unnecessary test
- adjust one test to actually test a regression and skip it because it fails
@dummdidumm
Copy link
Member

  • I moved the tests to puppeteer because JSdom does not support contenteditable
  • I tweaked one test which shows that this does not actually fix Updating a contenteditable w/ on:input function is prepending, not replacing, if initial value is empty #5018 (pressing enter and then typing something shows the bug, and the test is adjusted to do that programmatically)
  • I optimized for the case of contenteditable being statically analyzable
  • I reverted the unshift change because writing the test in a certain way shows that this introduces a regression (though it has a bug the other way around; I added a comment on the test for that)

In general I think comparing text nodes inside contenteditable is the wrong thing. I don't have a good idea how this could look like instead.

@dummdidumm dummdidumm merged commit a2170f5 into sveltejs:master Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Repeat words in plain text aren't reactive
3 participants