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

[camera][web] prevent creating a webworker in non-browser environments #27222

Merged
merged 2 commits into from
Feb 22, 2024

Conversation

marklawlor
Copy link
Contributor

Why

Fix #27194

Expo Router is rendering the page on the server, where the Worker global does not exist.

How

createWorkerAsyncFunction starts a webworker and returns a decode function. This function should never be called on the server (it should be from a user event), so when rendering on the server we stub the decode function and never create the webworker.

Test Plan

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Feb 22, 2024
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Feb 22, 2024
@lukmccall lukmccall changed the title (camera) prevent creating a webworker in non-browser environments [camera][web] prevent creating a webworker in non-browser environments Feb 22, 2024
@lukmccall lukmccall merged commit 0e1e5ae into main Feb 22, 2024
8 checks passed
@lukmccall lukmccall deleted the marklawlor/expo-camera/27194 branch February 22, 2024 09:47
aleqsio pushed a commit that referenced this pull request Feb 22, 2024
#27222)

# Why

Fix #27194

Expo Router is rendering the page on the server, where the Worker global does not exist.

# How

`createWorkerAsyncFunction` starts a webworker and returns a `decode` function. This function should never be called on the server (it should be from a user event), so when rendering on the server we stub the `decode` function and never create the webworker. 

# Test Plan

<!--
Please describe how you tested this change and how a reviewer could reproduce your test, especially if this PR does not include automated tests! If possible, please also provide terminal output and/or screenshots demonstrating your test/reproduction.
-->

# Checklist

<!--
Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin).
@brentvatne brentvatne added the published Changes from the PR have been published to npm label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint compatible bot: passed checks ExpoBot has nothing to complain about Camera published Changes from the PR have been published to npm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expo Router Tabs Sample Crashes when Using Expo Camera and Building For Web
5 participants