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

website: Fix sidebar in examples #1874

Merged
merged 8 commits into from
Dec 13, 2023
Merged

Conversation

zbigg
Copy link
Collaborator

@zbigg zbigg commented Dec 12, 2023

For #1501

Background

Change List

  • website: Fix sidebar in examples section
  • website: Fix DeviceTabs integration in luma-example, by recreating canvas and robust tracking of async process of initialization of device and animation loop
  • core: Device.destroy() exposed

@zbigg zbigg force-pushed the zbiggg/website-fix-examples-sidebar branch from 773a9e2 to 8067068 Compare December 12, 2023 10:02
@zbigg zbigg requested a review from ibgreen December 12, 2023 12:00
Copy link
Collaborator

@ibgreen ibgreen left a comment

Choose a reason for hiding this comment

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

This looks promising. Added some suggestions, fix anything that makes sense to you and then let's land!

website/src/react-luma/components/luma-example.tsx Outdated Show resolved Hide resolved

} else {
animationLoop = makeAnimationLoop(props.template as unknown as typeof AnimationLoopTemplate, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: put such a nasty cast on its own line?

Suggested change
animationLoop = makeAnimationLoop(props.template as unknown as typeof AnimationLoopTemplate, {
const animationLoopTemplate = props.template as unknown as typeof AnimationLoopTemplate;
animationLoop = makeAnimationLoop(animationLoopTemplate, {

const animationLoopRef = useRef<AnimationLoop | null>(null);
const [canvas, setCanvas] = useState<HTMLCanvasElement | null>(null);
const usedCanvases = useRef(new WeakMap())
const currentTask = useRef<Promise<any> | null>(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to type this Promise stronger, instead of any? This part is probably the most confusing in the new code, so comments and types will help.

console.log(`unmounting ${deviceType}`);
if (animationLoopRef.current) {
animationLoopRef.current.stop();
animationLoopRef.current.destroy();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to call both stop and destroy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

indeed, only destroy is needed

}

if (device) {
(device as any)?.destroy();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this cast needed? Seems like something we should fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added destroy to Device

@ibgreen
Copy link
Collaborator

ibgreen commented Dec 12, 2023

If you browse through the examples by clicking in the sidebar you will pretty quick crash the browser page. this is because WebGL contexts do not have a destroy method, and the limit on creating new contexts is fairly low (~10). Therefore it would be very advantageous to be able to reuse the canvas (reparenting it) when we switch example, as the webgl context is linked to the canvas. This would be a follow-up PR.

@zbigg zbigg force-pushed the zbiggg/website-fix-examples-sidebar branch from 7784baa to db09110 Compare December 13, 2023 09:37
@zbigg
Copy link
Collaborator Author

zbigg commented Dec 13, 2023

If you browse through the examples by clicking in the sidebar you will pretty quick crash the browser page. this is because WebGL contexts do not have a destroy method, and the limit on creating new contexts is fairly low (~10). Therefore it would be very advantageous to be able to reuse the canvas (reparenting it) when we switch example, as the webgl context is linked to the canvas. This would be a follow-up PR.

Didn't experienced it in my browser, but i know that certain environments have this limitation. Good idea.

@zbigg zbigg merged commit 2c98529 into master Dec 13, 2023
1 check passed
@zbigg zbigg deleted the zbiggg/website-fix-examples-sidebar branch December 13, 2023 12:05
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.

2 participants