table icon indicating copy to clipboard operation
table copied to clipboard

react table lose input focus on change. V 6.10 - 6.8.6

Open Oskii2311 opened this issue 7 years ago • 48 comments

Describe the bug Live https://codesandbox.io/s/6l7op9lovr After input value change, input is losing focus and we cannot type in more than 1 letter. When downgrade to 6.8.6 input is not losing focus after typing in 1 letter

To Reproduce Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/6l7op9lovr website
  2. Click first input
  3. try to write more than 1 letter in input
  4. check that input has lost focus
  5. downgrade to 6.8.6
  6. Click first input
  7. try to write more than 1 letter
  8. notice that it s possible now

Oskii2311 avatar May 09 '19 07:05 Oskii2311

I have the same problem.

kicomeister avatar May 17 '19 09:05 kicomeister

We are having same issue, Cell components seem to be unmounting and mounting whenever input value changes, which causes lost focus. With previous ver., this did not happened. https://codesandbox.io/s/reacttable-simple-table-6t7er?fontsize=14

wataru358 avatar May 21 '19 19:05 wataru358

Same here. Took a while to figure this out but luckily downgrade fixed it. I wonder how much will this change in v7

PeterKottas avatar May 29 '19 21:05 PeterKottas

@PeterKottas, v7 is going to be headless, so anything pertaining to markup, or actually rendering components will be in your hands. Please check out the alpha sandbox in the readme to get a feel for what will be possible.

tannerlinsley avatar May 30 '19 12:05 tannerlinsley

This is a major bug @tannerlinsley. It makes the tables totally unusable (double click is also failing for me because of lost focus).

I think just saying upgrade to v7 is not enough! Let's figure out which commit caused this issue and fix it!

tnrich avatar Sep 05 '19 15:09 tnrich

Indeed, it is a major bug.

I would love that! If you can find the bug and fix it, I will merge a PR for it.

tannerlinsley avatar Sep 05 '19 15:09 tannerlinsley

@tannerlinsley I'll take a peak, I do think you should probably revert/publish over v6.10 in the mean time

tnrich avatar Sep 05 '19 15:09 tnrich

This could mean removing and breaking a lot of features that people have PR'd in since then. Which version were you thinking?

tannerlinsley avatar Sep 05 '19 15:09 tannerlinsley

I'm doing some sleuthing on my end. Here is my best guess as to where the issue may have been introduced:

image

All the other changes between v6.8.6 and v.6.10 seem unlikely to have caused the issue to me.

You're maybe correct to hold off publishing over v6.10 if people are using the features they've added since. Let's try to find where this issue is arising

tnrich avatar Sep 05 '19 15:09 tnrich

Yep. I would rather find the issue and patch it, rather than take a step backwards. It's bad either way: existing users are either having issues with this bug right now, or will have compatibility issues if we reset.

tannerlinsley avatar Sep 05 '19 16:09 tannerlinsley

@tannerlinsley Ok, after playing with it a bit, it appears that the following change breaks double click for me:

image

I'm not sure if that change also causes the input focus loss that was the original issue filed here, but it definitely breaks double click for me.

@tannerlinsley what was that change meant to do?

Here I'm console logging "yar" on double click:

With v6.8 code:

function normalizeComponent (Comp, params = {}, fallback = Comp) {
  return typeof Comp === 'function' ? (
    Object.getPrototypeOf(Comp).isReactComponent ? (
      <Comp {...params} />
    ) : (
      Comp(params)
    )
  ) : (
    fallback
  )
}

dblclickissue_working

With v6.10 code:

function normalizeComponent (Comp, params = {}, fallback = Comp) {
  return typeof Comp === 'function' ? <Comp {...params} /> : fallback
}

dblclickissue

tnrich avatar Sep 05 '19 16:09 tnrich

Hmm.. This was a long time ago in dev years, but I think React deprecated or discouraged using isReactComponent. We needed a quick way to tell if a component was a class, function, or JSX.

It's likely that if we simply improve that function to handle all of those edge cases we'll be okay.

Not that this is perfect, but here is what we are working with in v7:

export function flexRender(Comp, props) {
  if (typeof Comp === 'function' || typeof Comp === 'object') {
    return <Comp {...props} />
  }
  return Comp
}

Currently, it doesn't handle detecting JSX primitives, so you have to do this: Header: () => <span>Yo</span>, instead of just Header: <span>Yo</span>. I wish it did detect this though.

tannerlinsley avatar Sep 05 '19 16:09 tannerlinsley

maybe we can follow the top voted answer here: https://stackoverflow.com/questions/33199959/how-to-detect-a-react-component-vs-a-react-element

?

tnrich avatar Sep 05 '19 17:09 tnrich

Hmm... 🤔 https://twitter.com/dan_abramov/status/787739945301635073

tannerlinsley avatar Sep 05 '19 17:09 tannerlinsley

It's really the difference between a react component and a react element.

A component is a class or function that has not been yet, and an element has already been into an React Element object.

tannerlinsley avatar Sep 05 '19 17:09 tannerlinsley

I meant this one: https://stackoverflow.com/a/41658173/2178112

tnrich avatar Sep 05 '19 17:09 tnrich

Yep. Those are perfect. We need to incorporate those into the render function for voth v6 and v7.

tannerlinsley avatar Sep 05 '19 18:09 tannerlinsley

Would you like to test those out and update the older function? I'll work on the v7 impl.

tannerlinsley avatar Sep 05 '19 18:09 tannerlinsley

Okay I put a PR in @tannerlinsley

tnrich avatar Sep 05 '19 20:09 tnrich

Merged.

tannerlinsley avatar Sep 05 '19 20:09 tannerlinsley