question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Last instance steals focus when multiple instances are present

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What’s the current behavior?

In my use case, I have two instances present, one for making edits, and another for previewing the result.

When multiple instances are present, and you make edits to any instance but the last in the DOM, the last instance steals focus. It then becomes impossible to focus any instance but the last.

I know this issue was fixed before, but perhaps it resurfaced post-0.50.0.

output2

Codesandbox: https://codesandbox.io/s/spike-slate-u8zpz

Slate: 0.57.1 Browser: Chrome OS: Mac

What’s the expected behavior?

When multiple instances are present, the user should be able to interact and edit an instance without another instance stealing focus.

Are there any potential workarounds?

In my use case, I only require one instance to be editable, so ensuring that this instance is last in the DOM is working for me.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
jagaapplecommented, Apr 11, 2020

As @CameronAckermanSEL said, to refer the same value occurs this bug. In my case, I need two or more editor components that don’t need shared texts, but they refer the same value as an initial value for useState like the following.

const initialValue = [{ type: "paragraph", children: [{ text: "" }] }];

const Component = () => {
  const editor = React.useMemo(() => withReact(createEditor()), []);
  const [value, setValue] = React.useState(initialValue);
  ...
};

In the above codes, initialValue is an object and the same objects have the same addresses in JavaScript, so I got this bugs. useState can accept a function which returns an initial value, I can give a function to it in order to prevent this bug.

https://codesandbox.io/s/slate-focus-bugs-8tsgy

In other cases, some custom plugins for Slate.js have an expensive process, so I made it to be memoized, but memoization shares the same value between caches. In the end, I stopped using memoization for these plugins.

3reactions
Haaxor1689commented, Feb 21, 2020

We have a bit different issue. Again 2 different instances of editor but the problem is that when clicking focus directly from one to another both seem to loose focus.

slate2

Read more comments on GitHub >

github_iconTop Results From Across the Web

New instances stealing focus : r/BlueStacks
Hi! This is expected behavior. With every other program, once it has been opened, it now becomes the program in focus and therefore...
Read more >
Windows 10 Randomly Loses Focus on Current ...
Scenario 2) I am actively typing in MS Word and my cursor disappears. ... It always takes focus when something is happening when...
Read more >
Preventing applications from stealing focus - windows
Show activity on this post. Ghacks has a possible solution: It happens several times a day that some applications steal the focus of...
Read more >
Visual Studio: How to stop breakpoint hit from stealing focus?
This is finally fixed in VS2019. Go to Tools->Options->Debugging->General, down at the bottom is "Bring Visual Studio to the foreground when breaking in...
Read more >
Crusade against focus stealing
Hereby, I convoke all IDEA users out there to gather together, and let our frustration be heard. It's a battle against the thieves,......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found