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

Check if document.getElementById('tabs-bar__portal') is null #11605

Closed
wants to merge 1 commit into from

Conversation

zunda
Copy link
Contributor

@zunda zunda commented Aug 19, 2019

While viewing LTL or FTL in multi-column mode, Javascript raises TypeError while narrowing the window:

shonbori

While I'm not fully sure what I'm doing, this change seems to prevent the error.

This seem to prevent TypeError when narrowing browser showing LTL or FTL.
@ClearlyClaire
Copy link
Contributor

I am afraid of two things with this change:

  • That instead of crashing, it would just display the column header within the column instead of above it (which admittedly is better than crashing, but would still lead ton inconsistent experience and be hard to debug)
  • That it may also happen for the ColumnBackButton component

@ClearlyClaire
Copy link
Contributor

The root issue is that the portal container and its content can be created in the same React render cycle, so whenever that happens, the target of the portal isn't in the DOM yet. This is obviously an issue, and I guess there ought to be a better way to achieve this, but I can't think of one.

Your patch does indeed prevent a crash and it does indeed make the header scroll within the column as opposed to stay on top like it should normally do.

One workaround I can think of is to add something to force the component to render again as long as the portal target doesn't exist, with something like:

this.setState({ forceReRender: !this.state.forceReRender });

@@ -178,7 +178,9 @@ class ColumnHeader extends React.PureComponent {
if (multiColumn || placeholder) {
return component;
} else {
return createPortal(component, document.getElementById('tabs-bar__portal'));
var e = document.getElementById('tabs-bar__portal');
if (e === null) return component;
Copy link
Contributor

Choose a reason for hiding this comment

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

This branch should force the component to re-render, as otherwise, the column header will not scroll properly.

@zunda
Copy link
Contributor Author

zunda commented Aug 19, 2019

@ThibG thanks so much for looking into this! It seems that the problem is far too much for my knowledge around React. May I close this PR and create an Issue so that you'd be able to take time to come up with a better solution?

@ClearlyClaire
Copy link
Contributor

Or I could add the workaround I suggested in this PR, if you don't mind?

@zunda
Copy link
Contributor Author

zunda commented Aug 20, 2019

Reported as an Issue at #11630 and closing this. Cheers!

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.

2 participants