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] unselect before navigation #2755

Merged
merged 5 commits into from Nov 11, 2021
Merged

Conversation

treenoder
Copy link
Contributor

fixes #1054

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
  • 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 pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Nov 6, 2021

🦋 Changeset detected

Latest commit: 356b436

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@bluwy bluwy added the router label Nov 7, 2021
packages/kit/src/runtime/client/utils.js Outdated Show resolved Hide resolved
packages/kit/src/runtime/client/router.js Outdated Show resolved Hide resolved
/** @type {import('test').TestMaker} */
export default function (test) {
test('reset selection', '/selection/a', async ({ page, clicknav }) => {
await page.waitForTimeout(50);
Copy link
Member

@bluwy bluwy Nov 7, 2021

Choose a reason for hiding this comment

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

Is there a reason to wait for timeout? We have tried to avoid this if possible. If it's really needed, we should add a comment explaining it.

1
);
await clicknav('[href="/selection/b"]');
await page.waitForTimeout(50);
Copy link
Member

Choose a reason for hiding this comment

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

And the timeout here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test was inconsistent without that timeout, on my setup at least. Maybe someone can run tests to confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't reproduce inconsistencies so waitForTimeout calls was removed. By the way, is there a docker file or something for contributors, to build/test project?

Copy link
Member

Choose a reason for hiding this comment

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

By the way, is there a docker file or something for contributors, to build/test project?

There isn't one that I know of, but I don't have much issues with local test inconsistencies in the past. Playwright ships its own chromium browser IIRC so that should eliminate most of the cross-machine quirks.

@bluwy bluwy changed the title [fix] Unselect before navigation [fix] unselect before navigation Nov 7, 2021
… the renderer.js:update method. removed waitForTimeout calls from test.
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

I have one small request below, but otherwise this looks good to me! Tests seem to pass too. I'll wait for Ben's comment on my question above before merging.

packages/kit/src/runtime/client/router.js Outdated Show resolved Hide resolved
@@ -275,6 +275,8 @@ export class Renderer {
this._init(navigation_result);
}

getSelection()?.removeAllRanges();

Copy link
Member

Choose a reason for hiding this comment

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

not exactly related to your change, but if (!opts) shouldn't the document.body.focus() line still be called? I don't quite get what that check is doing and wonder if it should be removed? maybe i'm just sleep deprived enough that I'm making a dumb mistake in reading this code...

Copy link
Member

Choose a reason for hiding this comment

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

I'm actually quite confused of the part inside if (!opts) too. When I refactored that, I tried to keep it as before. That means document.body.focus() and scrolling only happens if opts exist, I thought it was intentional.

If it wasn't, maybe we should refactor that again, and always do focusing and scrolling regardless of opts. We can do that in a separate PR though.

@Rich-Harris Rich-Harris merged commit 2a97b03 into sveltejs:master Nov 11, 2021
@Rich-Harris
Copy link
Member

excellent, thank you!

1
);
await clicknav('[href="/selection/b"]');
assert.equal(
Copy link
Member

Choose a reason for hiding this comment

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

i'm worried this might introduce flakiness, which is why you sometimes needed the timeout. I wonder if you need to wait until the selection is present instead of simply checking that it is

@rmunn
Copy link
Contributor

rmunn commented Nov 22, 2021

This is probably causing #2853.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Text selection is kept when switching between svelte routers - should be resetting?
5 participants