Skip to content

Fix race when starting the search - keep correct filter - #19765

Merged
krassowski merged 4 commits into
jupyterlab:mainfrom
krassowski:fix-search-race
Sep 16, 2026
Merged

krassowski merged 4 commits into
jupyterlab:mainfrom
krassowski:fix-search-race

Conversation

@krassowski

@krassowski krassowski commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

References

Code changes

  • Keep one pending mode change handler and cancel the previous one, so a handler scheduled by an earlier transition cannot run after a later one.
  • Check the notebook mode as it is when the deferred handler runs, which is the mode that _updateSelectionMode() acts on.
  • Cancel the pending handler on dispose.
  • Add unit tests for both orderings of the mode transitions.
  • Drop the 200 ms wait workaround from the Toggles search in line selection UI test.

50 local runs of Toggles search in line selection without the 200 ms wait:

success failure
before 41 9
after 50 0

User-facing changes

Before: pressing Ctrl+F with text selected in a cell sometimes reset the search filter from "Search in 1 Selected Line" to "Search in 1 Selected Cell", and the search then covered the whole cell.

After: the line selection is kept, and the search covers the selected lines.

Backwards-incompatible changes

None.

AI usage

  • Yes: Some or all of the content of this PR was generated by AI.
  • Yes: The human author has carefully reviewed this PR and run this code (keep this PR "draft" until the answer is YES)
  • AI tools and models used: Opus 5

@krassowski krassowski added this to the 4.6.x milestone Sep 14, 2026
@krassowski krassowski added the bug label Sep 14, 2026
@jupyterlab-probot

jupyterlab-probot Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

View the integration tests report in the browser: UI tests report

Comment thread packages/notebook/src/searchprovider.ts Outdated
private _onNotebookStateChanged(_: Notebook, args: IChangedArgs<unknown>) {
if (args.name === 'mode') {
if (this._delayedModeChangeHandler !== null) {
// Only the most recent mode transition is of interest.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we use a Debouncer from Lumino here, instead of handling the timeout ourself ?

@brichet brichet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @krassowski, LGTM

@krassowski
krassowski merged commit 2bb95ab into jupyterlab:main Sep 16, 2026
113 checks passed
@krassowski
krassowski deleted the fix-search-race branch September 16, 2026 09:21
@lumberbot-app

lumberbot-app Bot commented Sep 16, 2026

Copy link
Copy Markdown

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:
They assume that the base project is the Git remote upstream and your fork is origin.

  1. Update backport branch.
git fetch upstream 4.6.x:4.6.x
# or `git pull upstream 4.6.x` if you are on 4.6.x
  1. Create PR branch.
git switch -c auto-backport-of-pr-19765-on-4.6.x 4.6.x
  1. Cherry pick the first parent branch of this PR on top of the older branch:
git cherry-pick -x -m1 2bb95ab8870efffeedbc07190fb7b8699e6ba32f
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #19765: Fix race when starting the search - keep correct filter'
  1. Push to a named branch:
git push --set-upstream origin auto-backport-of-pr-19765-on-4.6.x
  1. Create a PR against branch 4.6.x, I would have named this PR:

Backport PR #19765 on branch 4.6.x (Fix race when starting the search - keep correct filter)

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

krassowski added a commit that referenced this pull request Sep 16, 2026
… - keep correct filter) (#19770)

Backport PR #19765 on
branch 4.6.x (Fix race when starting the search - keep correct filter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search in selection filter sometimes does not update from cell to line mode

2 participants