Repository navigation
fix (html5): Fix whiteboard crash on Safari versions <= 16 - #22764
Conversation
WalkthroughThe pull request introduces conditional logic in the HTML and build processes to accommodate Safari-specific requirements. In the HTML file, an IIFE detects the user’s browser via the user agent and dynamically injects the appropriate JavaScript bundle depending on whether the browser is Safari (version ≤ 16) or another browser. The build configuration is adjusted across multiple files: a new build script for Safari is added in the package configuration and Webpack uses an environment variable ( Sequence Diagram(s)Bundle Loading in HTMLsequenceDiagram
participant Browser as User's Browser
participant MainHTML as main.html Script
participant Head as Document Head
Browser->>MainHTML: Load page and execute IIFE
MainHTML->>MainHTML: Check navigator.userAgent for Safari and version
alt Safari (version ≤ 16)
MainHTML->>MainHTML: Set script src to "bundle.<hash>.safari.js"
else Other Browsers
MainHTML->>MainHTML: Set script src to "bundle.<hash>.js"
end
MainHTML->>Head: Append script element to <head>
Build and Deployment ProcesssequenceDiagram
participant DeployScript as deploy.sh / build.sh
participant FS as Filesystem
participant BuildSystem as NPM/Webpack
participant Server as Nginx
DeployScript->>FS: Remove "dist" directory (rm -rf dist)
DeployScript->>BuildSystem: Execute "npm run build-safari" (TARGET=safari)
BuildSystem-->>DeployScript: Safari bundle generated
DeployScript->>BuildSystem: Execute "npm run build" (TARGET=default)
BuildSystem-->>DeployScript: Default bundle generated
DeployScript->>FS: Extract bundle hash from generated files
DeployScript->>FS: Rename Safari bundle files to include hash
DeployScript->>FS: Copy files from "dist" to deployment location
DeployScript->>Server: Restart Nginx service
Suggested Reviewers
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
build/packages-template/bbb-html5/build.sh (2)
44-63: Improve hash extraction and error handlingWhile the renaming logic for Safari bundles is functional, there are some improvements that could be made:
- The script uses
ls | grepwhich can be problematic for certain filenames. Consider using a more robust approach.- There's no error handling if the
cd distcommand fails.#Rename all safari bundle with same hash of the last bundle -cd dist +cd dist || { echo "Failed to change directory to dist"; exit 1; } -HASH=$(ls | grep -Eo 'bundle\.[a-f0-9]{20}\.js' | head -n 1 | grep -Eo '[a-f0-9]{20}') +HASH=$(find . -maxdepth 1 -name "bundle.[a-f0-9]*.js" -type f | head -n 1 | grep -Eo '[a-f0-9]{20}')🧰 Tools
🪛 Shellcheck (0.10.0)
[warning] 46-46: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
(SC2010)
44-63: Consider extracting renaming logic to a shared scriptThe same renaming logic appears in both
build.shanddeploy.sh. Consider extracting this to a shared script to avoid duplication and make maintenance easier.🧰 Tools
🪛 Shellcheck (0.10.0)
[warning] 46-46: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
(SC2010)
bigbluebutton-html5/client/main.html (1)
171-189: Consider adding error handling for script loadingWhile the browser detection works well, there's no error handling if the script fails to load. Consider adding a fallback mechanism.
var script = document.createElement('script'); +script.onerror = function() { + console.error('Failed to load bundle, attempting to load fallback'); + var fallbackScript = document.createElement('script'); + fallbackScript.src = 'bundle.' + bundleHash + '.safari.js'; + document.head.appendChild(fallbackScript); +}; if (isSafari && safariVersion && safariVersion <= 16) { script.src = 'bundle.' + bundleHash + '.safari.js'; } else { script.src = 'bundle.' + bundleHash + '.js'; }bigbluebutton-html5/deploy.sh (1)
21-39: Improve error handling and hash extraction in deployment scriptSimilar to the build.sh file, there are some improvements that could be made:
- Add error handling for the
cd distcommand- Use a more robust approach than
ls | grepfor hash extraction-cd dist +cd dist || { echo "Failed to change directory to dist"; exit 1; } -HASH=$(ls | grep -Eo 'bundle\.[a-f0-9]{20}\.js' | head -n 1 | grep -Eo '[a-f0-9]{20}') +HASH=$(find . -maxdepth 1 -name "bundle.[a-f0-9]*.js" -type f | head -n 1 | grep -Eo '[a-f0-9]{20}')🧰 Tools
🪛 Shellcheck (0.10.0)
[warning] 21-21: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
(SC2164)
[warning] 22-22: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
(SC2010)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
bigbluebutton-html5/client/main.html(1 hunks)bigbluebutton-html5/deploy.sh(1 hunks)bigbluebutton-html5/package.json(1 hunks)bigbluebutton-html5/webpack.config.js(3 hunks)build/packages-template/bbb-html5/build.sh(1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
build/packages-template/bbb-html5/build.sh
[warning] 46-46: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
(SC2010)
bigbluebutton-html5/deploy.sh
[warning] 21-21: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
(SC2164)
[warning] 22-22: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
(SC2010)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: build-package (others)
- GitHub Check: build-package (bbb-html5)
- GitHub Check: build-package (bbb-graphql-server)
- GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (8)
build/packages-template/bbb-html5/build.sh (1)
41-42: New build process for Safari browsersThe addition of the Safari-specific build is well aligned with the PR objectives to address compatibility issues with Safari <= 16. This approach ensures different bundles for different browser targets.
bigbluebutton-html5/client/main.html (1)
171-189: Well-implemented browser detection and conditional bundle loadingThis is a clean implementation of conditional bundle loading based on browser detection. The approach correctly targets the issue described in the PR objectives by loading the non-minified bundle only for Safari <= 16.
bigbluebutton-html5/package.json (1)
7-8: Well-structured build scripts for different targetsThe addition of the TARGET environment variable and the new build-safari script provides a clean way to generate different bundles for different browser targets. This implementation is straightforward and effective.
bigbluebutton-html5/deploy.sh (1)
17-20: Added build process for Safari browsers in deploymentThe deployment script now correctly builds the Safari-specific bundle before the default one, which aligns with the PR objectives.
bigbluebutton-html5/webpack.config.js (4)
13-15: Clear target identification for Safari buildsThe addition of the Safari target flag is clearly implemented. The console log is helpful during development but consider if it's needed in production.
20-22: Dynamic filename generation based on targetThe conditional filename generation works well to create distinct bundles for Safari and other browsers.
35-49: Well-implemented template parameters for HTML generationThe addition of templateParameters ensures the bundle hash is correctly passed to the HTML template, which is essential for the conditional loading mechanism.
123-123: Effective solution for Safari compatibility issuesDisabling TerserPlugin for Safari builds is in line with the PR objectives, which mentioned that this was the only viable solution after extensive testing of various configurations. While this does result in a larger bundle size for Safari users (13MB vs 5.6MB), it successfully addresses the compatibility issues.
|
I included Safari 16 because while we know the unminified bundle isn’t needed for version 16.6, we’re unsure about earlier versions. To be safe, it made sense to cover all minor versions of 16. |
Automated tests Summary✅ All the CI tests have passed! |
gabriellpr
left a comment
There was a problem hiding this comment.
Now the user can join using Safari 15, just one thing to report, when the moderator creates polling and after publishing it, starts the screen sharing, then stops it, for the attendee will appear the message "something went wrong" for a couple of seconds, and then the whiteboard appears normally again.
This does not affect the user to use the bbb on Safari 15.
recording.12.webm
I'll take a look on this error. But I believe this error is not a blocker for merging the PR (since now the user can't even open the whiteboard). |



Issue
Safari browsers (<=16) fail to load the client properly due to issues caused by the
TerserPluginminification process, resulting in errors likeRight side of assignment cannot be destructuredand laterReferenceError: Can't find variable: HistoryManagerand related race conditions.Disabling
TerserPluginresolves these errors but significantly increases the bundle size (from5.6 MBto13 MB).Solution
The implemented solution generates two bundles:
This selective bundling guarantees that older Safari browsers work correctly without negatively impacting performance for other users.
Result
The client now successfully loads and functions correctly on Safari versions >= 14:

Specific bundles are loaded depending on the browser version:

Technical Details
Multiple configurations of
TerserPluginwere extensively tested (e.g., togglingcompress,mangle, and enablingsafari10support), including:https://stackoverflow.com/questions/57360588/how-to-use-terser-with-webpack
terser/terser#117
While these changes temporarily resolved some issues, they introduced new ones (likely race conditions), ultimately requiring the complete disabling of
TerserPluginfor Safari <=16.Errors: