-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
fix(BaseConfiguration): set devicePixelRatio
from window
#9470
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break SSR I believe
the question is why getEnv isn't called when the app starts |
It looks like you're right, this does break SSR. I am not sure how to call this at app start while allowing SSR to continue to function other than wrapping this in a conditional of Calling getEnv inside the constructor of StaticCanvas seems to work with the SSR codesandbox example, but is not eloquent. |
that is also breaking SSR |
In the example above this is the trace for getEnv's first run which is during The first use of |
I see 2 issues here:
Alternatively we need a custom node config class that has retinaScaling set to 1 and the browser version that default to window.devicepixelRatio. The config module could also just have a |
getEnv
to set devicePixelRatio
in index.tsdevicePixelRatio
from window
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the correct approach
No value can be set before loading or else SSR will break |
can you explain this a little bit better?
What are the tech constrain of SSR in your opinion and which are the one that we add on our own to make things easier for the devs |
fabric logic can't execute until the page loads in the client for SSR to work |
I think I should add an e2e SSR test, @asturur thoughts? |
This is how we solved the SSR issue ( |
@ShaMan123 for me the code as i see it at commit 61ba553 is the way i would have solved it. I agree the only issue we have to avoid is that importing fabric breaks the code in node. If the developer needs to use SSR to produce an SVG to add to the dom at rendering time ( i don't know to send a placeholder of the canvas that looks like the canvas and then swap it to interactive ) that can be done, importing the node version of fabric. |
If you do that you can't import fabric outside of ueEffect and you have to use dynamic imports |
@ShaMan123 why so? having a typeof window !== undefined in node code is totally fine imho. It doesn't break anything. On top of that the fact that we are calling a setConfig without dev consent, is a bit strange. |
can you explain why we should support changing the dpr apart from the dpr change event that we should support out of the box? |
Sticking to the bug report, since changing |
That is wrong. It is breaking. Will SSR run this line on import? If so it is breaking |
I asked to trace the call for a reason |
I still want to undersatnd why dpr is configurable |
To patch this you can call |
what do you mean by dpr? |
DevicePixelRatio |
@AdamMerrifield Sorry we got in a convoluted discussion over this PR, this PR was OK and we are going to merge it and then reiterate on additional improvements. |
We discussed this largely, this is a fix, we can follow up with concerns and larger changes
Motivation
closes #9464
Description
In the browser
window.devicePixelRatio
is not set to theconfig
object until the first run ofgetEnv
. This needs to run only on the browser instance of fabric.Changes
Add a
getEnv()
call to index.ts so it runs a single time in the browser to setconfig.devicePixelRatio
.In Action
https://jsfiddle.net/35Lxfq7v/1/