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

Use self to get global context before window in getEventPriority. #2493

Merged
merged 3 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/fiber/src/core/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ function makeId(event: Intersection) {
// https://github.com/facebook/react/tree/main/packages/react-reconciler#getcurrenteventpriority
// Gives React a clue as to how import the current interaction is
export function getEventPriority() {
let name = window?.event?.type
// Get a handle to the current global scope in window and worker contexts if able
// https://github.com/pmndrs/react-three-fiber/pull/2493
const globalScope = (typeof self !== 'undefined' && self) || (typeof window !== 'undefined' && window)
if (!globalScope) return DefaultEventPriority

const name = globalScope.event?.type
switch (name) {
case 'click':
case 'contextmenu':
Expand Down
3 changes: 2 additions & 1 deletion packages/fiber/src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export type ObjectMap = {
}

export function calculateDpr(dpr: Dpr) {
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], window.devicePixelRatio), dpr[1]) : dpr
const target = typeof window !== 'undefined' ? window.devicePixelRatio : 1
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr
}

/**
Expand Down