Skip to content

Jump to the next childDom if its _dom is null#1452

Merged
marvinhagemeister merged 4 commits into
preactjs:masterfrom
Almo7aya:fixReconciliation
Mar 27, 2019
Merged

Jump to the next childDom if its _dom is null#1452
marvinhagemeister merged 4 commits into
preactjs:masterfrom
Almo7aya:fixReconciliation

Conversation

@Almo7aya

Copy link
Copy Markdown
Contributor

I think this should fix #1343, but not other reconciliation issues like #1326

@coveralls

coveralls commented Mar 24, 2019

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling d9547e3 on Almo7aya:fixReconciliation into 6fac51e on developit:master.

@andrewiggins

Copy link
Copy Markdown
Member

Hi @Almo7aya! This is great! Thanks for taking the time to contribute a fix 🎉

Could you add test case so we don't regress this in the future?

@marvinhagemeister

Copy link
Copy Markdown
Member

Related: #1440

@Almo7aya

Copy link
Copy Markdown
Contributor Author

@andrewiggins I'm stuck with writing a test case for this, the saveFocus function does not let me check for moving children, it saves the focused child and refocused it after rendering, so I can't detect if the children moved or not. Have any idea how to do this? :)

@marvinhagemeister

marvinhagemeister commented Mar 26, 2019

Copy link
Copy Markdown
Member

@Almo7aya Let's use the code from #1343 as a test case 🎉

it('should not re-render when a component returns undefined', () => {
  let Dialog = () => undefined;
  let updateState;
  class App extends Component {
    constructor(props) {
      super(props);
      this.state = { name: '' };
      updateState = () => this.setState({ name: ', friend' });
    }

    render(props, { name }) {
      return (
        <div>
          <Dialog />
          <h1 class="fade-down">Hi{name}</h1>
        </div>
      );
    }
  }

  render(<App />, scratch);
  clearLog();

  updateState();
  rerender();

  // We don't log text updates
  expect(getLog()).to.deep.equal([]);
});

EDIT: I can also confirm that this fixes #1343. Just checked it out locally 👍

@Almo7aya

Copy link
Copy Markdown
Contributor Author

@marvinhagemeister Sorry!, but even this doesn't work, it always passes. The problem is children reconciler append children at the end of the parent not in their correct position this cause starting the animation, I cannot detect if the children were appended at the end or at their correct position using insertBefore 🤦‍♂️!!

@marvinhagemeister

Copy link
Copy Markdown
Member

@Almo7aya are you sure? The test only passes with the changes from your PR. It fails in master.

@Almo7aya

Copy link
Copy Markdown
Contributor Author

@marvinhagemeister I think I have some problems with my testing environment if you are sure that this fails in master and passes with this PR I'll commit your test case anyway?!

@marvinhagemeister

Copy link
Copy Markdown
Member

@Almo7aya Good idea, we can always check if it runs properly in Travis here 👍

@Almo7aya

Almo7aya commented Mar 26, 2019

Copy link
Copy Markdown
Contributor Author

@marvinhagemeister

Copy link
Copy Markdown
Member

@Almo7aya Oh right, I found why it always passes. Our test logger needs to be set up for it to work. We usually do it in the test runners before hook:

import { logCall } from '../_util/logCall';

describe("render()", () => {
  // ...

  before(() => {
    logCall(Element.prototype, 'appendChild');
    logCall(Element.prototype, 'insertBefore');
    logCall(Element.prototype, 'removeChild');
    logCall(Element.prototype, 'remove');
  });

  // ...
});

Only once it's attached to a prototype it will start logging DOM operations.

@Almo7aya

Copy link
Copy Markdown
Contributor Author

@marvinhagemeister That's great, thank you 🎉!

Comment thread src/diff/children.js Outdated
Comment thread src/diff/children.js Outdated

@marvinhagemeister marvinhagemeister left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome, thank you so much for your PR 🎉 Left 2 last really minor and admittedly nitpicky comments and I think it's ready to go on 👍💯 Let me know what you think :)

@Almo7aya

Copy link
Copy Markdown
Contributor Author

@marvinhagemeister I think it's ready now. Thank you for your help, I didn't know about loggers functions in the test utils. Again thank you!🎉.

@marvinhagemeister marvinhagemeister changed the title Jumb to the next childDom if its _dom is null Jump to the next childDom if its _dom is null Mar 27, 2019
@marvinhagemeister marvinhagemeister merged commit 8b92933 into preactjs:master Mar 27, 2019
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.

10.0.0-alpha.0 - Returning undefined redraws the component tree

4 participants