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

Resizing height issue #521 #573

Merged
merged 9 commits into from
Sep 2, 2019
Merged

Resizing height issue #521 #573

merged 9 commits into from
Sep 2, 2019

Conversation

paulathevalley
Copy link
Contributor

@paulathevalley paulathevalley commented Aug 27, 2019

Description

This PR addresses this resizing height issue documented from the README:

Resizing Height Issue

When using dynamic content in a slide such as text, you may see an issue with resizing the height of the component when loading in an iframe, or forcing the component to load synchronously after another component such as a loading screen, or interstitial.

How resizing works

In componentDidMount, the initial dimensions are assigned to each slide:

  • Width: initialSlidewidth || slideWidth || (slidesToShow / width of container)
  • Height: initialSlideHeight

Once the component has completed mounting with the accurate width, it waits for the readyStateChange event to fire before measuring the desired height of the content (current, first, max). That measurement then replaces initialSlideHeight with the measured height in pixels.

If the readyStateChange event fires before the component completes mounting, the height of the component is not measured until a resize event or a change in slide is triggered.

It does so by tracking the readystatechange listener in addition to whether the component is mounted (through this.mounted). If both are true, and there is a mismatch in the height, then componentDidUpdate will run again, and the Carousel will recalculate the height and width.

I think this solution gets at the symptoms rather than the underlying issue, which is an ordering problem with two events that.. as far as I’m aware, are outside our control. I would like to spend more time on a more elegant solution, but this may suffice for fixing bugs in the meantime.

Fixes #521

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

How Has This Been Tested?

I was having trouble reproducing the issue locally, but I was able to reproduce it consistently by commenting out this.setDimensions() in onReadyStateChange().

Checklist: (Feel free to delete this section upon completion)

  • I have added tests that prove my fix is effective or that my feature works

@paulathevalley paulathevalley changed the title [WIP - NO REVIEW] Resizing height issue [WIP - NO REVIEW] Resizing height issue #521 Aug 27, 2019
@paulathevalley paulathevalley changed the title [WIP - NO REVIEW] Resizing height issue #521 Resizing height issue #521 Aug 27, 2019
@@ -199,8 +197,6 @@ In componentDidMount, the initial dimensions are assigned to each slide:

Once the component has completed mounting with the accurate width, it waits for the readyStateChange event to fire before measuring the desired height of the content (`current`, `first`, `max`). That measurement then replaces `initialSlideHeight` with the measured height in pixels.

If the readyStateChange event fires before the component completes mounting, the height of the component is not measured until a resize event or a change in slide is triggered.

Copy link
Contributor

@jflayhart jflayhart Aug 28, 2019

Choose a reason for hiding this comment

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

I think there should at least be a helpful disclaimer explaining if setDimensions is run before, let's say, an image loads, then the slide height is not measured again until a subsequent resize event occurs. I have run into this issue before and found a hard workaround, unless this PR truly fixes that issue.

For example, I currently must to do something like this with React refs in my codebase, otherwise the image is completely cut off:

<img onLoad={this.carouselRef.setDimensions()} />

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was the intent of this PR! I did my best to reproduce the issue, but I am not certain if it was sufficient. Did you find any differently?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! @paulathevalley Let me get back to you on this, sorry for the delay. I'll update to latest version and see if your PR fixes issue. Will provide screenshots.

Copy link
Contributor

Choose a reason for hiding this comment

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

@paulathevalley @sarmeyer Still an issue D:

Screen Shot 2019-09-03 at 3 34 23 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

noooo!! Do you have more details on how you reproduced it? Were you able to reproduce it locally consistently? I would love to understand more clearly.

@sarmeyer sarmeyer merged commit c2487a3 into master Sep 2, 2019
@sarmeyer sarmeyer deleted the bug/resize-event branch January 14, 2020 21:56
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.

Miscalculation of width or height on first paint until there is resize event
3 participants