-
Notifications
You must be signed in to change notification settings - Fork 33
Calendar missing headers on initial render with Preact #8
Comments
Interesting! I wonder if setting a |
As you mentioned, I doubt that this is a Preact issue. |
Scrap that! I thought I had used that package but I was wrong, this is handled in the |
Also, is there a public URL I can look at the component in action myself? If not, no worries. |
Thank you for getting back so quickly! I tried setting a width: 100% to the calendar class in my css, but the same situation still happens.. and these screenshots are the results I get: the console returns 0 as the availableWidth every time... code:
|
Apologies if that wasn't what you wanted, I wasn't sure what you meant by adding tracelogs... I also do not have a public url yet.. |
Alright, that's what I wanted. Although you should note that If you try setting an explicit width to <div className="calendar" style={{ width: 400 }}>
<AvailableTimes
... and some props
/>
</div> |
Hello! I set the width using inline styles like you suggested and the headers still does not appear on initial load... Currently looks like this screenshot: http://i.imgur.com/7Rm6dIE.png |
Interesting. Are you doing server-side rendering by any chance? Also, if you log |
I am not using server-side rendering And When I log element.getBoundingClientRect(): http://i.imgur.com/KZ1yLBt.png |
Is that with the inline width? I wonder what’s going on here... if you inspect the parent div in the browser, does it also show you a dimension-less element? |
Correct, that is with the inline width, the parent div just has a default sizing from fitting in the child component that contains the react-available-times calendar. I think I made some progress in finding out the issue, actually. To investigate further since yesterday, I tried using this package on a fresh react app that I made using create-react-app, and I found that in the React project, there was nothing wrong with the package and everything worked as intended out of the box. To investigate further, I have actually downloaded the source code and made it as a component in my Preact project, (I just had to change some module exports and imports in 3 files and put it under components/react-availble-calendar and it worked the same way). And upon digging into the source code a bit, I noticed that Preact is known for not supporting Refs out of the box, but if you have Preact-compat installed (which I do), it lets you work with string refs in preact. So I think this could be an issue with Preact and how it handles Refs. Perhaps you could shine light on your reasoning behind the Thanks for your time, I appreciate the help! |
I'm using You might be on to something with the React/Preact discrepancy, but from my end it looks like the I'm going to release version 1.2.1 that will allow you to pass in a |
Didn't mean to close this issue (github did it for me because I had tagged the issue in a commit). |
Alright, if you install v1.2.1 you can pass a |
Thanks for the new tag! However, I've been playing around with v1.2.1 and I'm sad to say the same issue still happens 😞 I can pass down the width property (either as a 100% or a pixel number value), but that just sets the width of the entire component, and does not take care of the headers not appearing on initial load. It seemed like you got this working in Preact on your end, could I possibly see the code you did to get the package to render completely on initial load? Thanks again! |
Update: I've found that the refs offset are always 0, so in the code when it does element.offsetWidth and sets that to availableWidth prop, the availableWidth prop is getting set to 0. I'm seeing the same behaviour in Week.jsx with daysRef as well, where the offset of that is always returning 0, and setting available width to 0. Perhaps as a solution we could set the width that's being passed down as a prop from AvailableTimes to the other components as well, so that we could set the availablewidth for the initial load of the calendar. Thanks! |
I haven't had time to test things in Preact. So I'm mostly just making assumptions based on what you are reporting.
I guess that would work, although I prefer to have one source of truth here. In lieu of a public URL where I can test this, would you mind sharing the css involved in rendering the page? You can share as a gist if it's too long to add here in a comment. |
@trotzig Another interesting fact, if you resize the window the headers work ok 🤷♂️ |
Hi @clucasalcantara, sorry for the late response here. As far as I know, no one is actively working on this. I'd be very happy to merge a PR fixing this! |
Hello,
I tried using this component with my Preact project and I noticed something odd. When the component using react-available times first renders, it renders like this image (hosted on imgur) http://i.imgur.com/u90KQhM.png
and then, when I resize the window, (e.g., I right click and open the developer console in chrome) it looks like this: http://i.imgur.com/a7Jid5U.png
I don't think it's Preact that's the issue, since Preact is just a lightweight version of React. What I've noticed is that the
AvailableWidth
prop gets passed down and that's what gets used to set the initial width of the headers. However, I think the problem is that the available width prop gets set to 0 upon initial load.What is a good way I can fix this / workaround this? I would like the calendar to load fully upon initial render, and not have to have the window resized to make the headers show up.
Thank you in advance!
Here is my code to reproduce:
The text was updated successfully, but these errors were encountered: