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

Sporadic formatting issues (rendered text too narrow) #1702

Closed
kodster28 opened this issue Sep 14, 2023 · 9 comments
Closed

Sporadic formatting issues (rendered text too narrow) #1702

kodster28 opened this issue Sep 14, 2023 · 9 comments
Labels

Comments

@kodster28
Copy link

Occasionally (very difficult to reproduce), we've noticed the footnote content rendering very narrowly (in a way that doesn't quite match the container).

Screenshot 2023-09-14 at 11 12 30
@kodster28
Copy link
Author

kodster28 commented Sep 14, 2023

At least in our repo, think we can get around it by setting the following property explicitly?

.littlefoot__content {
  width: 100% !important;
}

Testing with width: some lower % seems to repro the behavior.
Live demo

Screenshot
Screenshot 2023-09-14 at 10 16 19 AM

@goblindegook
Copy link
Owner

Interesting, thanks for reporting this. Are you using the pre-release versions? Which browsers have you found the issue on?

@kodster28
Copy link
Author

kodster28 commented Sep 18, 2023

Chrome, at least in terms of what folks were reporting.

Not using any pre-release versions. Was using 4.0.0-9, but recently upgraded to 4.0.0-10.

@goblindegook
Copy link
Owner

Released 4.0.0-11 with some changes that will hopefully address the issue. Please let me know if you continue to notice it.

@kodster28
Copy link
Author

Absolutely will do, thanks!!

@nqst
Copy link

nqst commented Feb 13, 2024

Hey folks, thanks for making a great package!

This problem seems to be still relevant, even after updating to the last version:

image

The possible culprit is that .littlefoot__wrapper has dynamically added max-width: 40px in its style attribute. If I remove it in Web inspector, the problem is gone.

@goblindegook goblindegook reopened this Feb 13, 2024
@kevin1
Copy link
Contributor

kevin1 commented May 7, 2024

I guess this is probably the culprit:

wrapper.style.maxWidth = content.offsetWidth + 'px'

kevin1 added a commit to kevin1/littlefoot that referenced this issue May 15, 2024
goblindegook#1702

If the page is resized before any footnotes have been opened, the
`resize` action can compute a very small `max-width` based on zero size
footnote contents. This was allowed to happen because `isMounted` always
returns true after the popover element is created but not yet shown.

- `isMounted` now checks whether the popover is contained in the DOM.
- `createElementFromHTML` now unwraps newly created elements to improve
  robustness in case `parentElement` gets used elsewhere.
@kevin1
Copy link
Contributor

kevin1 commented May 15, 2024

I am able to reproduce the issue with these steps:

  1. Reload the page
  2. Resize the browser window before any footnotes have been opened
  3. Open a footnote

Resizing the page causes this to run:

resize: () => {
if (isMounted(popover)) {
popover.style.left = getLeftInPixels(content, button) + 'px'
wrapper.style.maxWidth = content.offsetWidth + 'px'
repositionTooltip(popover, button)
}

The code computes a very small max-width value because content.offsetWidth is zero when the footnote is not mounted, which is always true on first load.

This should be gated by isMounted, which is checking for popover.parentElement:

const isMounted = (popover: HTMLElement) => !!popover.parentElement

Because of the way elements are created during littlefoot setup, popover.parentElement is always an empty div on first load:

function createElementFromHTML(html: string): HTMLElement {
const container = document.createElement('div')
container.innerHTML = html
return container.firstElementChild as HTMLElement

@goblindegook
Copy link
Owner

Thanks for investigating the issue!

goblindegook pushed a commit that referenced this issue May 16, 2024
#1702

If the page is resized before any footnotes have been opened, the
`resize` action can compute a very small `max-width` based on zero size
footnote contents. This was allowed to happen because `isMounted` always
returns true after the popover element is created but not yet shown.

- `isMounted` now checks whether the popover is contained in the DOM.
- `createElementFromHTML` now unwraps newly created elements to improve
  robustness in case `parentElement` gets used elsewhere.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants