Skip to content

fix (html5): Fix whiteboard crash on Safari versions <= 16 - #22764

Merged
antobinary merged 2 commits into
bigbluebutton:v3.0.x-releasefrom
gustavotrott:fix-wb-safari15
Mar 24, 2025
Merged

antobinary merged 2 commits into
bigbluebutton:v3.0.x-releasefrom
gustavotrott:fix-wb-safari15

Conversation

@gustavotrott

@gustavotrott gustavotrott commented Mar 23, 2025 •

Copy link
Copy Markdown
Contributor

Issue

Safari browsers (<=16) fail to load the client properly due to issues caused by the TerserPlugin minification process, resulting in errors like Right side of assignment cannot be destructured and later ReferenceError: Can't find variable: HistoryManager and related race conditions.
Disabling TerserPlugin resolves these errors but significantly increases the bundle size (from 5.6 MB to 13 MB).

Solution

The implemented solution generates two bundles:

  • Minified bundle (5.6 MB): Served to modern browsers and Safari versions >16.
  • Non-minified bundle (13 MB): Served exclusively to older Safari versions (<=16), ensuring functionality without errors.

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:
Safari Working

Specific bundles are loaded depending on the browser version:
Dedicated Bundle Load

Technical Details

Multiple configurations of TerserPlugin were extensively tested (e.g., toggling compress, mangle, and enabling safari10 support), including:

new TerserPlugin({
  terserOptions: {
    safari10: true,
    mangle: { ie8: true }
  }
}),

new TerserPlugin({
  terserOptions: {
    compress: false,
    mangle: false,
  }
}),

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 TerserPlugin for Safari <=16.

Errors:

image
image
image

@gustavotrott gustavotrott added this to the Release 3.0 milestone Mar 23, 2025
@coderabbitai

coderabbitai Bot commented Mar 23, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The 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 (TARGET) to generate a distinct bundle name for Safari builds. The deployment script is updated to run the Safari build prior to the default build, remove the old build directory, extract a hash from the generated bundles, and then rename Safari-specific files to include this hash. Finally, the script copies the files to a target location and restarts the Nginx service.

Sequence Diagram(s)

Bundle Loading in HTML

sequenceDiagram
    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>
Loading

Build and Deployment Process

sequenceDiagram
    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
Loading

Suggested Reviewers

  • ramonlsouza
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
build/packages-template/bbb-html5/build.sh (2)

44-63: Improve hash extraction and error handling

While the renaming logic for Safari bundles is functional, there are some improvements that could be made:

  1. The script uses ls | grep which can be problematic for certain filenames. Consider using a more robust approach.
  2. There's no error handling if the cd dist command 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 script

The same renaming logic appears in both build.sh and deploy.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 loading

While 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 script

Similar to the build.sh file, there are some improvements that could be made:

  1. Add error handling for the cd dist command
  2. Use a more robust approach than ls | grep for 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

📥 Commits

Reviewing files that changed from the base of the PR and between cd1f6ce and 835d224.

📒 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 browsers

The 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 loading

This 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 targets

The 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 deployment

The 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 builds

The 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 target

The conditional filename generation works well to create distinct bundles for Safari and other browsers.


35-49: Well-implemented template parameters for HTML generation

The 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 issues

Disabling 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.

@gustavotrott

Copy link
Copy Markdown
Contributor Author

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.

@github-actions

Copy link
Copy Markdown

Automated tests Summary

✅ All the CI tests have passed!

@gustavotrott gustavotrott changed the title fix (html5): Whiteboard not working for Safari <= 16 fix (html5): Fix whiteboard crash on Safari versions <= 16 Mar 24, 2025
@ramonlsouza
ramonlsouza requested a review from gabriellpr March 24, 2025 13:36

@gabriellpr gabriellpr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@gustavotrott

Copy link
Copy Markdown
Contributor Author

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).

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