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

Fix: initial canvas size computation in createRoot #2406

Merged
merged 4 commits into from
Aug 4, 2022

Conversation

kmannislands
Copy link
Contributor

@kmannislands kmannislands commented Jul 28, 2022

As @Madou noted here, the clientTop used in the previous MR around

Seems this would only effect users of direct createRoot and not Canvas but still worth correcting.

Did a small amount of boyscoutting to remove lets and improve types here. The notable change is using a typeguard to throw at the top of createRoot if the supplied element is not a canvas. This allows cleaner typings after the guard. Specifically, the same canvas variable is later passed to createRendererInstance where it is cast to HTMLCanvasElement and I assume would fail if the cast is inaccurate. Happy to revert this part of the change if it is not desired.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 28, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 596a67d:

Sandbox Source
example Configuration

@@ -3,12 +3,12 @@ import { Root } from './renderer'
import { RootState, Subscription } from './store'

type GlobalRenderCallback = (timeStamp: number) => void
type SubItem = {callback: GlobalRenderCallback}
type SubItem = { callback: GlobalRenderCallback }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated formatting changes caused by running lint locally. Is eslint not checked in CI?

Copy link
Member

Choose a reason for hiding this comment

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

We have husky hooks for housekeeping on commit, but prettier won't fail a PR. Doesn't work when people edit directly in GitHub though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you be open to a PR that adds lint checking in CI?

Copy link
Member

Choose a reason for hiding this comment

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

IMO good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great. Opened #2420

function createRoot<TCanvas extends Element>(canvas: TCanvas): ReconcilerRoot<TCanvas> {
if (!elementIsCanvas(canvas)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I may be missing context here. The generic TCanvas seems strange since it seems like this function wouldn't work if canvas is an arbitrary element other than canvas.

Copy link
Member

@CodyJasonBennett CodyJasonBennett Jul 29, 2022

Choose a reason for hiding this comment

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

Indeed. Although I'd prefer to check with instanceof HTMLCanvasElement if it works for OffscreenCanvas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've improved this to handle OffscreenCanvas explicitly and split this work out to hopefully allow the less controversial bug fix here to go ahead:
kmannislands#2

I'll re-target this PR to r3f if there's appetite for the change.

Copy link
Member

Choose a reason for hiding this comment

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

I'd have to defer to @joshuaellis on how to type this in kmannislands#2. I'm a little wary of consuming types from @types/three rather than fixing upstream.

@CodyJasonBennett CodyJasonBennett merged commit 6289c78 into pmndrs:master Aug 4, 2022
@kmannislands kmannislands deleted the fix-size-computation branch August 4, 2022 19:54
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.

3 participants