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

fix: sdk loading snippet to reduce ambiguity in updating url #2048

Merged
merged 3 commits into from
Feb 19, 2025

Conversation

saikumarrs
Copy link
Member

@saikumarrs saikumarrs commented Feb 18, 2025

PR Description

I've updated the SDK loading snippet to split the variables that form the final URL of the core SDK.
sdkBaseUrl - refers to the CDN URL without the version
sdkVersion - refers to the SDK version
sdkFileName - refers to the SDK file name on the CDN

This will be helpful for the customers who setup custom domains and have to update the snippet to just replace RS CDN URL with theirs, leaving aside the version and the file name.

Linear task (optional)

https://linear.app/rudderstack/issue/SDK-2942/update-sdk-loading-snippet-to-decouple-the-sdk-major-version-and

Cross Browser Tests

Please confirm you have tested for the following browsers:

  • Chrome
  • Firefox
  • IE11

Sanity Suite

  • All sanity suite test cases pass locally

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Summary by CodeRabbit

  • New Features

    • Incremented the RudderSnippet version from "3.0.58" to "3.0.60".
    • Introduced new configuration variables: window.rudderAnalyticsBuildType, sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode.
  • Refactor

    • Streamlined the SDK loading process to include explicit version details in the URL, ensuring more predictable asset retrieval.
    • Enhanced the clarity and maintainability of the code by separating the SDK version and file name into distinct variables.
  • Bug Fixes

    • Updated error handling logic to check for undefined directly instead of using void 0.

@saikumarrs saikumarrs self-assigned this Feb 18, 2025
@saikumarrs saikumarrs requested a review from a team as a code owner February 18, 2025 14:53
Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

📝 Walkthrough

Walkthrough

This pull request updates several components of the RudderStack SDK. The Rollup configuration modifies the terser plugin settings by removing the sdkName variable and adding sdkVersion and sdkFileName. In the SDK loading scripts, the construction of the SDK URL is revised to separate the base URL and version, with sdkName renamed to sdkFileName. Additionally, the version of the RudderSnippet is incremented to "3.0.60" across various files, and error handling logic is refined to use undefined instead of void 0.

Changes

File(s) Change Summary
packages/loading-scripts/rollup.config.mjs Updated terser plugin settings: removed sdkName; added sdkVersion to the top_retain array and sdkFileName to the reserved array.
packages/loading-scripts/src/index.ts Revised SDK URL construction: split the original base URL to separate out the version (sdkVersion set to 'v3') and renamed sdkName to sdkFileName.
examples/angular/sample-app/src/index.html Incremented RudderSnippetVersion to "3.0.60"; added window.rudderAnalyticsBuildType, sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode. Updated error handling logic.
examples/integrations/Ninetailed/sample-apps/app-using-v3-cdn/public/index.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, sdkFileName, and updated script loading logic.
examples/nextjs/hooks/sample-app/src/app/layout.tsx Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
examples/nextjs/js/sample-app/src/app/layout.js Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
examples/nextjs/page-router/sample-app/src/pages/_document.tsx Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
examples/nextjs/ts/sample-app/src/app/layout.tsx Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
examples/reactjs/hooks/sample-app/public/index.html Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
examples/reactjs/js/sample-app/public/index.html Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
examples/reactjs/ts/sample-app/public/index.html Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
examples/reactjs/vite/sample-app/index.html Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
examples/v3-beacon/index.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
examples/v3-legacy-minimum-plugins/index.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
examples/v3-legacy/index.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
examples/v3-minimum-plugins/index.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
examples/v3/index.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
packages/analytics-js/fixtures/msw.handlers.ts Updated HTTP GET request handler to target ${dummyCDNHost}/v3/modern/${SDK_FILE_NAME}.
packages/analytics-js/tests/nativeSdkLoader.js Updated loadingSnippet function to reflect version change and variable renaming.
packages/analytics-js/public/index.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
packages/sanity-suite/public/v3/index-cdn.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
packages/sanity-suite/public/v3/index-local.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
packages/sanity-suite/public/v3/index-npm-bundled.html Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
packages/sanity-suite/public/v3/index-npm.html Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
packages/sanity-suite/public/v3/integrations/index-cdn.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
packages/sanity-suite/public/v3/integrations/index-local.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
packages/sanity-suite/public/v3/integrations/index-npm-bundled.html Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
packages/sanity-suite/public/v3/integrations/index-npm.html Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
packages/sanity-suite/public/v3/manualLoadCall/index-cdn.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
packages/sanity-suite/public/v3/manualLoadCall/index-local.html Incremented RudderSnippetVersion to "3.0.60"; modified sdkBaseUrl, added sdkVersion, and updated error handling logic.
packages/sanity-suite/public/v3/manualLoadCall/index-npm-bundled.html Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.
packages/sanity-suite/public/v3/manualLoadCall/index-npm.html Incremented RudderSnippetVersion to "3.0.60"; added configuration variables for SDK and updated error handling logic.

Possibly Related PRs

  • fix: loading snippet to unmangle reserved variables #1771: The changes in the main PR are related to the modifications in the rollup.config.mjs file regarding the handling of reserved variables, specifically the addition of sdkVersion and sdkFileName to the top_retain and reserved arrays, which aligns with the focus on variable management in the retrieved PR.
  • chore: fix globalThis polyfill in loading snippet #1821: The changes in the main PR, which involve modifications to the rollup.config.mjs file affecting the sdkName and sdkVersion variables, are related to the changes in the retrieved PR, which also modifies the handling of globalThis in the context of the Rudder SDK, as both PRs deal with the SDK's configuration and loading mechanisms.
  • fix: improve sdk loading snippet #1745: The changes in the main PR are related to those in the retrieved PR as both involve modifications to the SDK loading process, specifically addressing the handling of the sdkName and sdkVersion variables, and improving the script loading logic.

Suggested Reviewers

  • MoumitaM
  • ChryssaAliferi
  • koladilip

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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.

Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.36%. Comparing base (9199de2) to head (c290ddf).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2048   +/-   ##
========================================
  Coverage    61.36%   61.36%           
========================================
  Files          478      478           
  Lines        16402    16402           
  Branches      3228     3224    -4     
========================================
  Hits         10065    10065           
+ Misses        5149     5131   -18     
- Partials      1188     1206   +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (1)
packages/loading-scripts/src/index.ts (1)

24-26: Consider using environment variables for better maintainability.

While the separation of URL components improves clarity, hardcoding values like sdkVersion and sdkBaseUrl might make future updates more challenging. Consider using environment variables similar to how __WRITE_KEY__ is handled.

-    const sdkBaseUrl = 'https://cdn.rudderlabs.com';
-    const sdkVersion = 'v3';
-    const sdkFileName = 'rsa.min.js';
+    const sdkBaseUrl = '__SDK_BASE_URL__';
+    const sdkVersion = '__SDK_VERSION__';
+    const sdkFileName = '__SDK_FILE_NAME__';

Then update the replace plugin configuration in rollup.config.mjs:

      replace({
        preventAssignment: true,
+       __SDK_BASE_URL__: process.env.SDK_BASE_URL || 'https://cdn.rudderlabs.com',
+       __SDK_VERSION__: process.env.SDK_VERSION || 'v3',
+       __SDK_FILE_NAME__: process.env.SDK_FILE_NAME || 'rsa.min.js',
        // ... other replacements
      }),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c676168 and 3958d38.

📒 Files selected for processing (2)
  • packages/loading-scripts/rollup.config.mjs (2 hunks)
  • packages/loading-scripts/src/index.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Bundle size checks
  • GitHub Check: Security and code quality checks
  • GitHub Check: Unit Tests and Lint
🔇 Additional comments (2)
packages/loading-scripts/rollup.config.mjs (1)

80-83: LGTM! The terser configuration correctly preserves the new variables.

The addition of sdkVersion and sdkFileName to both top_retain and reserved arrays ensures these variables remain intact during minification, which is essential for the SDK loading snippet to work correctly.

Also applies to: 95-98

packages/loading-scripts/src/index.ts (1)

129-133: LGTM! The URL construction is now more maintainable.

The new URL construction pattern clearly separates the base URL, version, build type, and file name, making it easier for customers to update individual components, especially when using custom domains.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 18, 2025
Copy link

github-actions bot commented Feb 18, 2025

size-limit report 📦

Name Size (Base) Size (Current) Size Limit Status
Cookies Utils - Legacy - NPM (ESM) 1.54 KB 1.54 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (CJS) 1.75 KB 1.75 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (UMD) 1.54 KB 1.54 KB (0%) 2 KB
Cookies Utils - Modern - NPM (ESM) 1.17 KB 1.17 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (CJS) 1.4 KB 1.4 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (UMD) 1.16 KB 1.16 KB (0%) 1.5 KB
Plugins Module Federation Mapping - Legacy - CDN 332 B 332 B (0%) 512 B
Plugins Module Federation Mapping - Modern - CDN 331 B 331 B (0%) 512 B
Plugins - Legacy - CDN 13.66 KB 13.66 KB (0%) 14 KB
Plugins - Modern - CDN 5.64 KB 5.64 KB (0%) 6 KB
Common - No bundling 17.93 KB 18.02 KB (+0.49% ▲) 18.4 KB
Load Snippet 762 B 765 B (+0.4% ▲) 1 KB
Core (v1.1) - NPM (ESM) 30.13 KB 30.13 KB (0%) 32 KB
Core (v1.1) - NPM (CJS) 30.33 KB 30.33 KB (0%) 32 KB
Core (v1.1) - NPM (UMD) 30.17 KB 30.17 KB (0%) 32 KB
Core (Content Script - v1.1) - NPM (ESM) 29.64 KB 29.64 KB (0%) 30.5 KB
Core (Content Script - v1.1) - NPM (CJS) 29.89 KB 29.89 KB (0%) 30.5 KB
Core (Content Script - v1.1) - NPM (UMD) 29.74 KB 29.74 KB (0%) 30.5 KB
Core (v1.1) - Legacy - CDN 31.99 KB 31.99 KB (0%) 32.5 KB
Core (v1.1) - Modern - CDN 30.06 KB 30.06 KB (0%) 32 KB
Service Worker - Legacy - NPM (ESM) 30.55 KB 30.55 KB (0%) 31 KB
Service Worker - Legacy - NPM (CJS) 30.84 KB 30.84 KB (0%) 31 KB
Service Worker - Legacy - NPM (UMD) 30.64 KB 30.64 KB (0%) 31 KB
Service Worker - Modern - NPM (ESM) 25.73 KB 25.73 KB (0%) 26 KB
Service Worker - Modern - NPM (CJS) 25.96 KB 25.96 KB (0%) 26.5 KB
Service Worker - Modern - NPM (UMD) 25.71 KB 25.71 KB (0%) 26 KB
Core - Legacy - NPM (ESM) 47.34 KB 47.34 KB (0%) 48 KB
Core - Legacy - NPM (CJS) 47.62 KB 47.62 KB (0%) 48 KB
Core - Legacy - NPM (UMD) 47.4 KB 47.4 KB (0%) 48 KB
Core - Legacy - CDN 47.49 KB 47.49 KB (0%) 47.5 KB
Core - Modern - NPM (ESM) 26.85 KB 26.85 KB (0%) 27 KB
Core - Modern - NPM (CJS) 27.08 KB 27.08 KB (0%) 27.1 KB
Core - Modern - NPM (UMD) 26.87 KB 26.87 KB (0%) 27 KB
Core - Modern - CDN 27.08 KB 27.08 KB (0%) 27.5 KB
Core (Bundled) - Legacy - NPM (ESM) 47.34 KB 47.34 KB (0%) 48 KB
Core (Bundled) - Legacy - NPM (CJS) 47.62 KB 47.62 KB (0%) 48 KB
Core (Bundled) - Legacy - NPM (UMD) 47.4 KB 47.4 KB (0%) 48 KB
Core (Bundled) - Modern - NPM (ESM) 38.59 KB 38.59 KB (0%) 39 KB
Core (Bundled) - Modern - NPM (CJS) 38.88 KB 38.88 KB (0%) 39 KB
Core (Bundled) - Modern - NPM (UMD) 38.57 KB 38.57 KB (0%) 39 KB
Core (Content Script) - Legacy - NPM (ESM) 47.31 KB 47.31 KB (0%) 48 KB
Core (Content Script) - Legacy - NPM (CJS) 47.57 KB 47.57 KB (0%) 48 KB
Core (Content Script) - Legacy - NPM (UMD) 47.31 KB 47.31 KB (0%) 48 KB
Core (Content Script) - Modern - NPM (ESM) 38.51 KB 38.51 KB (0%) 39 KB
Core (Content Script) - Modern - NPM (CJS) 38.79 KB 38.79 KB (0%) 39 KB
Core (Content Script) - Modern - NPM (UMD) 38.58 KB 38.58 KB (0%) 39 KB
All Integrations - Legacy - CDN 94.94 KB 94.94 KB (0%) 95.3 KB
All Integrations - Modern - CDN 90.5 KB 90.5 KB (0%) 91 KB

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (6)
examples/angular/sample-app/src/index.html (1)

12-12: Consider externalizing the CDN URL.

While the introduction of separate variables improves clarity, consider externalizing the hardcoded CDN URL (https://cdn.rudderlabs.com) to a configuration file for better maintainability.

-          var sdkBaseUrl = "https://cdn.rudderlabs.com";
+          var sdkBaseUrl = window.RUDDERSTACK_CDN_URL || "https://cdn.rudderlabs.com";

Also applies to: 23-27

examples/integrations/Ninetailed/sample-apps/app-using-v3-cdn/public/index.html (1)

36-38: Minification and Error Handling Note.
In this minified snippet, the error check still uses void 0 (e.g., null===(n=window[e][r])||void 0===n||n.apply(...)). This is common in minified outputs for size optimization. If intentional, no action is needed; otherwise, consider verifying that the unminified counterparts use the more readable undefined for consistency.

packages/sanity-suite/public/v3/manualLoadCall/index-local.html (1)

178-188: Ensure Manual Load Form Functionality
The manual load functionality via the form submission is intact. The script correctly captures form inputs and calls window.manualLoad with parsed JSON load options. Verify that users are provided clear error messages if the JSON parsing fails. Consider adding client-side validation for better UX.

packages/sanity-suite/public/v3/manualLoadCall/index-cdn.html (1)

47-49: Introduction of New Variables for SDK URL Construction
New variables are introduced:
sdkBaseUrl now holds "https://cdn.rudderlabs.com",
sdkVersion is set to "__CDN_VERSION_PATH__", and
sdkFileName is set to "rsa.min.js".

This clearly decouples the URL components. Please confirm that using the placeholder "__CDN_VERSION_PATH__" is intentional (likely to be replaced during your build/deployment process).

examples/v3-legacy/index.html (1)

41-44: Commented-Out Modern Build Logic
There is a try-catch block (testing modern build capability via a dynamic Function) that’s currently commented out. Please confirm whether this is intentional; if modern build support is not required for legacy examples, this is acceptable, but if there’s a plan to re-enable it, consider adding a TODO comment for clarity.

examples/v3-beacon/index.html (1)

86-86: Refine SDK Script URL Construction
The URL is now composed using the new variables, which aligns with decoupling the version from the base URL. For improved readability, consider using template literals. For example:

- window.rudderAnalyticsAddScript("".concat(sdkBaseUrl, "/").concat(sdkVersion, "/").concat(window.rudderAnalyticsBuildType, "/").concat(sdkFileName), "data-rsa-write-key", "__WRITE_KEY__");
+ window.rudderAnalyticsAddScript(`${sdkBaseUrl}/${sdkVersion}/${window.rudderAnalyticsBuildType}/${sdkFileName}`, "data-rsa-write-key", "__WRITE_KEY__");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3958d38 and 5ebe326.

📒 Files selected for processing (30)
  • examples/angular/sample-app/src/index.html (3 hunks)
  • examples/integrations/Ninetailed/sample-apps/app-using-v3-cdn/public/index.html (1 hunks)
  • examples/nextjs/hooks/sample-app/src/app/layout.tsx (3 hunks)
  • examples/nextjs/js/sample-app/src/app/layout.js (3 hunks)
  • examples/nextjs/page-router/sample-app/src/pages/_document.tsx (3 hunks)
  • examples/nextjs/ts/sample-app/src/app/layout.tsx (3 hunks)
  • examples/reactjs/hooks/sample-app/public/index.html (3 hunks)
  • examples/reactjs/js/sample-app/public/index.html (3 hunks)
  • examples/reactjs/ts/sample-app/public/index.html (3 hunks)
  • examples/reactjs/vite/sample-app/index.html (3 hunks)
  • examples/v3-beacon/index.html (4 hunks)
  • examples/v3-legacy-minimum-plugins/index.html (4 hunks)
  • examples/v3-legacy/index.html (4 hunks)
  • examples/v3-minimum-plugins/index.html (4 hunks)
  • examples/v3/index.html (4 hunks)
  • packages/analytics-js/__fixtures__/msw.handlers.ts (1 hunks)
  • packages/analytics-js/__tests__/nativeSdkLoader.js (4 hunks)
  • packages/analytics-js/public/index.html (5 hunks)
  • packages/sanity-suite/public/v3/index-cdn.html (4 hunks)
  • packages/sanity-suite/public/v3/index-local.html (4 hunks)
  • packages/sanity-suite/public/v3/index-npm-bundled.html (3 hunks)
  • packages/sanity-suite/public/v3/index-npm.html (3 hunks)
  • packages/sanity-suite/public/v3/integrations/index-cdn.html (4 hunks)
  • packages/sanity-suite/public/v3/integrations/index-local.html (4 hunks)
  • packages/sanity-suite/public/v3/integrations/index-npm-bundled.html (3 hunks)
  • packages/sanity-suite/public/v3/integrations/index-npm.html (3 hunks)
  • packages/sanity-suite/public/v3/manualLoadCall/index-cdn.html (4 hunks)
  • packages/sanity-suite/public/v3/manualLoadCall/index-local.html (4 hunks)
  • packages/sanity-suite/public/v3/manualLoadCall/index-npm-bundled.html (3 hunks)
  • packages/sanity-suite/public/v3/manualLoadCall/index-npm.html (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
packages/analytics-js/__fixtures__/msw.handlers.ts (1)
Learnt from: saikumarrs
PR: rudderlabs/rudder-sdk-js#1867
File: packages/analytics-js/__fixtures__/msw.handlers.ts:86-86
Timestamp: 2024-11-12T15:14:33.334Z
Learning: When updating test files to replace 'example.com' with 'dummy.dataplane.host.com', note that the change is only needed for test suites that actually make network requests.
packages/analytics-js/__tests__/nativeSdkLoader.js (1)
Learnt from: saikumarrs
PR: rudderlabs/rudder-sdk-js#1708
File: packages/analytics-js/__tests__/nativeSdkLoader.js:31-33
Timestamp: 2024-11-12T15:14:23.319Z
Learning: The loading snippet in `packages/analytics-js/__tests__/nativeSdkLoader.js` is a standard part of the SDK, and no changes are desired on it.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Bundle size checks
  • GitHub Check: Security and code quality checks
  • GitHub Check: Unit Tests and Lint
🔇 Additional comments (88)
examples/nextjs/page-router/sample-app/src/pages/_document.tsx (2)

12-12: LGTM! Improved URL construction and configuration.

The separation of URL components into distinct variables (sdkBaseUrl, sdkVersion, sdkFileName) makes it easier for customers to update the CDN URL while keeping the version and file name intact. The addition of scriptLoadingMode explicitly indicates async loading.

Also applies to: 23-27


37-37: Improved readability in error handling.

The change from void 0 to undefined enhances code readability by using the more explicit keyword.

examples/nextjs/js/sample-app/src/app/layout.js (1)

20-46: Changes match the previously reviewed file.

The modifications are identical to those in _document.tsx and serve the same purpose.

examples/nextjs/hooks/sample-app/src/app/layout.tsx (1)

21-46: Changes match the previously reviewed file.

The modifications are identical to those in _document.tsx and serve the same purpose.

examples/nextjs/ts/sample-app/src/app/layout.tsx (2)

21-46: Changes match the previously reviewed file.

The modifications are identical to those in _document.tsx and serve the same purpose.


1-63: Verify cross-browser compatibility.

While the changes are primarily structural and don't introduce browser-specific features, please ensure testing across Chrome, Firefox, and IE11 as mentioned in the PR objectives.

packages/analytics-js/__fixtures__/msw.handlers.ts (1)

114-114: LGTM! URL path updated to include explicit version.

The change to include "/v3/modern/" in the URL path aligns with the new URL structure and improves clarity.

packages/analytics-js/__tests__/nativeSdkLoader.js (4)

4-4: LGTM! Version bump to 3.0.59.

Version update is consistent across all files.


17-18: LGTM! Introduced clear variable names for URL components.

The introduction of sdkVersion and sdkFileName variables improves clarity and makes URL updates easier for customers using custom domains.


29-29: LGTM! More explicit undefined check.

Changed from void 0 to undefined for better readability.


79-79: LGTM! Improved URL construction.

The new URL construction using template literals and separate variables makes it clearer and easier to maintain.

examples/reactjs/vite/sample-app/index.html (1)

11-11: Same feedback as Angular sample app.

The hardcoded CDN URL should be externalized for better maintainability.

Also applies to: 22-26

examples/reactjs/js/sample-app/public/index.html (3)

31-31: Update RudderSnippetVersion to 3.0.59.
The snippet version has been correctly incremented from "3.0.58" to "3.0.59", which aligns with the intended release update.


42-46: Introduce New SDK Configuration Variables.
New variables—window.rudderAnalyticsBuildType, sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode—are added to clearly decouple and define the CDN URL, version, and file name. This makes it easier for customers to update only the base URL if needed.


55-57: Clarify Error Handling Check.
The error handling on method invocation now explicitly uses === undefined (instead of void 0), which improves readability. Ensure that similar updates are applied consistently throughout the codebase.

examples/reactjs/ts/sample-app/public/index.html (3)

31-31: Update RudderSnippetVersion to 3.0.59.
The updated snippet version reflects the latest release. This change is consistent with the overall SDK update.


42-46: Add New SDK URL Components.
Adding sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode provides a modular approach to constructing the SDK URL. This should help decouple versioning from the URL, especially for custom domain setups.


55-57: Enhance Error Handling Readability.
The updated check using (_methodName = window[identifier][methodName]) === null || _methodName === undefined || _methodName.apply(...) is more explicit. Ensure that this pattern is uniformly used in all similar snippets.

examples/reactjs/hooks/sample-app/public/index.html (3)

31-31: Update RudderSnippetVersion to 3.0.59.
The change in the snippet version is applied correctly, which keeps this sample app up-to-date with the latest SDK version.


42-46: Configure SDK URL Components.
The introduction of sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode streamlines the configuration process. This modular approach aids in maintainability and easier customization for users.


55-57: Improve Method Invocation Error Handling.
The simplified error handling check (using === undefined instead of void 0) increases clarity. Please verify that similar changes are implemented in all snippets across frameworks.

examples/integrations/Ninetailed/sample-apps/app-using-v3-cdn/public/index.html (3)

29-29: Update RudderSnippetVersion in Minified Snippet.
The snippet now shows "3.0.59" immediately upon invocation. Although this file is minified, the version update is evident and correct.


33-34: Set New SDK Configuration Variables in Minified Code.
Within the minified snippet, the introduction of window.rudderAnalyticsBuildType, sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode is clear. This enables flexible script URL construction.


39-40: Dynamic Build Type Adjustment via Compatibility Check.
The try-catch block using new Function(...) updates window.rudderAnalyticsBuildType to "modern" if the test passes. Double-check that this dynamic adjustment meets all target browser requirements (including IE11) and does not disrupt legacy behavior.

packages/sanity-suite/public/v3/index-npm.html (3)

35-35: Update RudderSnippetVersion to 3.0.59.
The snippet’s version is correctly updated to "3.0.59", reflecting the latest SDK release.


46-50: Introduce New SDK URL Parameters.
The addition of window.rudderAnalyticsBuildType, sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode enhances clarity and modularity in loading the SDK. This change simplifies updates for custom domain users.


59-61: Simplify Undefined Check in Method Invocation.
The error handling statement now explicitly checks for undefined rather than using void 0, which improves readability. Ensure that this update is applied consistently across all similar scripts.

packages/sanity-suite/public/v3/index-npm-bundled.html (3)

35-35: Version Update:
The update of window.RudderSnippetVersion to "3.0.59" correctly reflects the new release version as outlined in the PR objectives.


46-50: Introduction of New SDK Configuration Variables:
The addition of window.rudderAnalyticsBuildType = "legacy", sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode clearly decouples the CDN URL, version, and file name. This enhancement improves clarity for customers with custom domains and aligns perfectly with the PR objectives.


59-61: Enhanced Error Handling Clarity:
Updating the check from using void 0 to undefined (as seen in the error-handling condition on line 60) improves readability and explicitly communicates the intended check. Verify that this change maintains the same runtime behavior as before.

packages/sanity-suite/public/v3/manualLoadCall/index-npm-bundled.html (3)

35-35: Version Update:
The snippet version update to "3.0.59" is consistent with the rest of the codebase and ensures that the SDK is correctly versioned.


46-50: New Variable Declarations for SDK Loading:
The new variables (window.rudderAnalyticsBuildType, sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode) have been introduced to improve the modularity of the SDK URL construction. This makes it straightforward for users to update only the CDN URL if needed.


59-61: Refined Error Handling Check:
The updated condition for method invocation now uses undefined instead of void 0 to check for the existence of _methodName. This change improves clarity without altering functionality.

packages/sanity-suite/public/v3/manualLoadCall/index-npm.html (2)

35-35: Version Bump Verification:
Changing window.RudderSnippetVersion from "3.0.58" to "3.0.59" meets the versioning requirements outlined in the PR.


46-50: Consistent Configuration Updates:
The insertion of new variables (window.rudderAnalyticsBuildType, sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode) standardizes the SDK loading snippet across files. This consistent approach ensures that customers can easily modify the base URL while the version and file name remain fixed.

packages/sanity-suite/public/v3/integrations/index-npm.html (3)

35-35: Uniform Version Update:
Upgrading window.RudderSnippetVersion to "3.0.59" maintains alignment with the updated SDK build across various integrations.


46-50: Standardized New SDK Variables:
The new declarations for window.rudderAnalyticsBuildType, sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode follow the established pattern. This improves maintainability and reduces ambiguity when customers adjust the CDN details.


59-61: Improved Error Handling Clarity:
The check using undefined for _methodName now makes the intent explicit. Ensure that this minor refactor does not affect any edge-case behavior.

packages/sanity-suite/public/v3/integrations/index-npm-bundled.html (3)

35-35: Consistent Versioning Update:
The update of window.RudderSnippetVersion to "3.0.59" is applied consistently with other files, ensuring uniformity across the SDK integration examples.


46-50: New SDK Parameters Introduced:
The addition of window.rudderAnalyticsBuildType, along with sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode, enhances the clarity of the SDK’s URL construction. This explicit separation helps customers update only what is necessary (e.g., the CDN base URL) and keeps the version and file name intact.


59-61: Explicit Error Handling Improvement:
Modifying the error-handling check to use undefined instead of void 0 increases the code's self-documentation. This change should be verified to behave identically to the previous implementation.

packages/sanity-suite/public/v3/index-local.html (5)

35-35: Update SDK Version Number
The snippet version has been updated to "3.0.59", which clearly communicates the current version. Ensure that any downstream consumers of this value are aware of the update.


47-49: Introduce Separate URL Components
New variables sdkBaseUrl, sdkVersion, and sdkFileName are introduced to decouple the SDK URL into distinct parts. This improves clarity for customers switching custom domains. Confirm that the chosen values (e.g. "v3" for sdkVersion) correctly reflect the intended deployment configuration.


60-61: Modernize Undefined Checks
The error handling now uses an explicit undefined check (i.e.

(_methodName = window[identifier][methodName]) === null || _methodName === undefined || ...

) instead of void 0. This enhances readability and aligns with modern JavaScript practices.


92-98: Clarify Global Object Retrieval
The inline function that defines getGlobal now uses a named function declaration. This not only improves readability but may also help debugging in environments like IE11. Please ensure cross-browser testing confirms that the global object is correctly detected.


110-110: Reference for Alternative SDK Loading
The commented-out script-loading line now reflects the updated URL construction using sdkVersion and sdkFileName. It serves as an informative reference. Ensure that any future reactivation of this code segment uses the proper variable values.

packages/sanity-suite/public/v3/index-cdn.html (4)

35-35: Update SDK Snippet Version
window.RudderSnippetVersion is now set to "3.0.59". This update is consistent with the overall versioning improvements.


47-49: Define CDN URL Variables with Placeholder
The new variables—sdkBaseUrl set to "https://cdn.rudderlabs.com", sdkVersion set to "__CDN_VERSION_PATH__", and sdkFileName set to "rsa.min.js"—clearly decouple the URL components. The use of "__CDN_VERSION_PATH__" as a placeholder suggests that a build or deployment process will substitute the correct value. Ensure that this substitution is reliably performed in the pipeline.


60-61: Consistent Undefined Handling
As with the local index file, the error handling now explicitly checks for undefined. This consistency strengthens the code quality and readability.


68-70: Validate Modern Build Type Fallback
The try-catch block that attempts to switch rudderAnalyticsBuildType to "modern" remains intact. Confirm that the detection of modern JS features is sufficient for your browser support matrix, especially for legacy browsers like IE11.

packages/sanity-suite/public/v3/integrations/index-local.html (4)

35-35: Update SDK Version Identifier
The SDK snippet version has been updated to "3.0.59". This helps downstream code quickly determine the new version.


47-49: Establish New URL Variables
New variables sdkBaseUrl, sdkVersion (with value "__CDN_VERSION_PATH__" as a placeholder), and sdkFileName are now defined. This separation simplifies future updates. Please verify that the placeholder value is correctly replaced during deployment.


60-61: Maintain Consistent Undefined Check
The update to check explicitly against undefined in place of void 0 improves the code clarity.


110-110: Commented Out Script Injection Update
The commented-out script-loading line now uses the new variables. While still inactive, this serves as a useful reference for the intended URL construction.

packages/sanity-suite/public/v3/integrations/index-cdn.html (5)

35-35: Reflect Updated SDK Version
The SDK snippet version is updated to "3.0.59", aligning with other parts of the codebase.


47-49: Breakout of URL Components for CDN
The introduction of sdkBaseUrl, sdkVersion (set to "__CDN_VERSION_PATH__"), and sdkFileName clarifies the URL structure. This approach reduces ambiguity for customers who need to customize their CDN URL. Ensure that "__CDN_VERSION_PATH__" is dynamically replaced as intended.


60-61: Enhance Undefined Checks
Switching to an explicit undefined check in the error handler improves the explicitness and readability of the code.


92-98: Named getGlobal Function for Better Clarity
The refactored, named getGlobal function is easier to read and debug. Confirm that this refactor does not affect the behavior in any targeted platform.


110-110: Active Script URL Construction
The call to window.rudderAnalyticsAddScript now actively constructs the URL using sdkBaseUrl, sdkVersion, window.rudderAnalyticsBuildType, and sdkFileName. This is a clear improvement for maintainability.

packages/sanity-suite/public/v3/manualLoadCall/index-local.html (3)

35-35: Upgrade SDK Version Number for Manual Load Call
The version has been updated to "3.0.59", which should be consistently reflected in all SDK load mechanisms.


47-49: Introduce Decoupled URL Variables for Manual Load
The new variable definitions (sdkBaseUrl as "https://cdn.rudderlabs.com", sdkVersion as "__CDN_VERSION_PATH__", and sdkFileName as "rsa.min.js") improve the clarity of how the SDK URL is constructed. This structure helps customers and developers update the SDK URL with minimal friction.


60-61: Maintain Consistent Error Checks
Updating the error handling to explicitly check against undefined remains consistent with other snippet files. This is a good practice and aids in cross-browser consistency.

packages/sanity-suite/public/v3/manualLoadCall/index-cdn.html (3)

35-35: Version Update Consistency
The snippet version has been updated to "3.0.59". This change is consistent with the overall SDK version bump and ensures that deployments pick up the new release.


60-60: Enhanced Undefined Check in Method Invocation
The updated check

(_methodName = window[identifier][methodName]) === null || _methodName === undefined || _methodName.apply(window[identifier], arguments);

now uses an explicit comparison to undefined rather than relying on void 0. This improves code clarity in error handling.


110-110: Updated Script URL Construction
The SDK script tag is now inserted using a URL built from the new variables:

window.rudderAnalyticsAddScript("".concat(sdkBaseUrl, "/").concat(sdkVersion, "/").concat(window.rudderAnalyticsBuildType, "/").concat(sdkFileName), "data-rsa-write-key", "__WRITE_KEY__");

This approach should simplify future updates, especially for customers using custom domains. Please verify that the final URL is resolving as expected in your test environments.

examples/v3/index.html (4)

11-11: Version Increment Update
window.RudderSnippetVersion is updated to "3.0.59". This aligns the example with the current release.


23-25: Separation of SDK Components
The introduction of distinct variables —
sdkBaseUrl as "https://cdn.rudderlabs.com",
sdkVersion as "v3", and
sdkFileName as "rsa.min.js"
improves modularity in URL construction and makes future updates (especially for custom domain scenarios) easier to manage.


36-36: Explicit Undefined Check in Method Invocation
Changing the check from using a non-explicit value (such as void 0) to a clear undefined check enhances readability and maintainability.


86-86: Dynamic Script Loading URL Construction
The final URL used in the script injection is now built dynamically (using .concat on the new variables). This ensures that the SDK load path reflects the new structure. Please confirm that this updated pattern supports both legacy and modern build types as intended.

examples/v3-legacy/index.html (3)

11-11: Legacy Example Version Update
The legacy example now reflects the updated window.RudderSnippetVersion set to "3.0.59", ensuring consistency with the latest SDK.


23-25: Refactored URL Variables in Legacy Example
New variables — sdkBaseUrl, sdkVersion (set to "v3"), and sdkFileName (replacing sdkName) — are introduced to simplify URL construction. Please verify that this change won’t disrupt any integrations that depend on the former hardcoded layout.


86-86: Script Loading URL Update for Legacy Build
The concatenation of sdkBaseUrl, sdkVersion, and sdkFileName in the URL now aligns with the modular approach. Double-check this in your legacy environments to ensure no unintended side effects occur.

examples/v3-minimum-plugins/index.html (4)

11-11: SDK Version Update Applied
The snippet version is updated to "3.0.59", ensuring that the minimum plugins example is in sync with the overall SDK version.


23-25: Modular SDK URL Component Introduction
The separation into sdkBaseUrl ("https://cdn.rudderlabs.com"), sdkVersion ("v3"), and sdkFileName ("rsa.min.js") clarifies the URL-building logic and simplifies future configuration changes.


86-86: Dynamic Script Injection
The updated script injection correctly builds the source URL with the new variables. Ensure that this logic passes in all environments, especially where the plugins functionality is critical.


98-102: Addition of Plugins Configuration
A new plugins array containing 'StorageEncryption' and 'XhrQueue' is now included in the load options. Confirm that these plugins are available and that their inclusion meets your integration requirements.

examples/v3-legacy-minimum-plugins/index.html (4)

11-11: Consistent Version Update in Legacy Minimum Plugins Example
The updated version "3.0.59" is now reflected here, bringing this legacy example in line with the rest of the codebase.


23-25: Modularization of SDK URL Variables
The refactoring from a hardcoded sdkName to distinct variables (sdkBaseUrl, sdkVersion with "v3", and sdkFileName) improves clarity and maintainability. This is especially helpful for users updating their integrations.


86-86: Dynamic URL Construction for Legacy Minimum Plugins
The method for constructing the script URL now uses the new variable pattern, ensuring consistency with other examples. Make sure this does not adversely affect legacy behaviors.


98-102: Consistency in Plugins Configuration
The plugins configuration remains consistent with the minimum plugins example, which is beneficial for predictable behavior. Please verify that both 'StorageEncryption' and 'XhrQueue' are the intended values for plugin activation.

examples/v3-beacon/index.html (3)

11-11: Update Snippet Version
The snippet version has been updated from "3.0.58" to "3.0.59" as per the PR objectives. This ensures that customers are aware of the latest SDK release.


23-25: Introduce SDK URL Components
The new variables (sdkBaseUrl, sdkVersion, and sdkFileName) decouple the CDN base URL from the version and filename. This improves clarity and maintainability—especially for customers updating custom domains.


36-36: Clarify Undefined Check in Method Dispatch
The updated check now explicitly compares against undefined (instead of using void 0), which enhances readability. Please ensure that this change is consistent with other parts of the codebase.

packages/analytics-js/public/index.html (5)

13-13: Update Snippet Version Consistently
The snippet version has been updated to "3.0.59" to match other parts of the SDK. This unified versioning across the codebase avoids ambiguity.


25-27: Introduce SDK URL Components in Public Index
The addition of sdkBaseUrl, sdkVersion, and sdkFileName here mirrors the changes in other files. This makes it easier for users to update only the CDN URL when needed.


38-38: Consistent Undefined Check in Method Invocation
The method invocation now explicitly checks for undefined before calling the method. This clarification improves code readability and maintains consistent error handling.


69-86: Enhanced GlobalThis Polyfill
The polyfill for globalThis has been updated with a dedicated getGlobal function that checks for both self and window. This explicit polyfill approach is clear, but you might also consider leveraging a well-tested polyfill library if cross-environment compatibility expands.


171-182: Review Environment Variables Check
The conditions that check envDestSDKBaseURL, envPluginsSDKBaseURL, and envConfigUrl compare against the string 'undefined'. If these placeholders are intended to be replaced during build time, this is acceptable; however, if they can be actual JavaScript undefined values, a typeof check (e.g., typeof envDestSDKBaseURL !== 'undefined') might be more robust. Please verify that these checks align with your build/replacement process.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 18, 2025
@saikumarrs saikumarrs force-pushed the fix.loading-snippet-sdk-2942 branch from 5ebe326 to 31321e8 Compare February 19, 2025 08:03
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (3)
packages/sanity-suite/public/v3/integrations/index-npm-bundled.html (1)

46-50: New SDK Configuration Variables Added.
The introduction of window.rudderAnalyticsBuildType, sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode enhances clarity by isolating the core SDK URL components. This will aid users employing custom domains to update only the required element without affecting the version or file name.
Consider adding inline documentation/comments for these variables to improve long-term maintainability and ease of use by other developers.

packages/sanity-suite/public/v3/manualLoadCall/index-npm.html (1)

46-50: Introduced New Variables for SDK URL Construction
The addition of sdkBaseUrl, sdkVersion, sdkFileName, and scriptLoadingMode makes the snippet’s URL components explicit and easier to update for custom domains. Consider using const instead of var for these variables if their values are immutable for improved code safety and readability. For example:

-            var sdkBaseUrl = "https://cdn.rudderlabs.com";
-            var sdkVersion = "v3";
-            var sdkFileName = "rsa.min.js";
-            var scriptLoadingMode = "async";
+            const sdkBaseUrl = "https://cdn.rudderlabs.com";
+            const sdkVersion = "v3";
+            const sdkFileName = "rsa.min.js";
+            const scriptLoadingMode = "async";
packages/sanity-suite/public/v3/manualLoadCall/index-local.html (1)

110-110: Document the New SDK URL Composition Example
The commented-out script-loading line now accurately reflects the new mechanism for constructing the SDK URL using sdkBaseUrl, sdkVersion, and sdkFileName. While it remains commented, please verify that if re-enabled, this pattern correctly concatenates the URL segments and that the replacement for __WRITE_KEY__ is handled appropriately.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ebe326 and c290ddf.

📒 Files selected for processing (32)
  • examples/angular/sample-app/src/index.html (3 hunks)
  • examples/integrations/Ninetailed/sample-apps/app-using-v3-cdn/public/index.html (1 hunks)
  • examples/nextjs/hooks/sample-app/src/app/layout.tsx (3 hunks)
  • examples/nextjs/js/sample-app/src/app/layout.js (3 hunks)
  • examples/nextjs/page-router/sample-app/src/pages/_document.tsx (3 hunks)
  • examples/nextjs/ts/sample-app/src/app/layout.tsx (3 hunks)
  • examples/reactjs/hooks/sample-app/public/index.html (3 hunks)
  • examples/reactjs/js/sample-app/public/index.html (3 hunks)
  • examples/reactjs/ts/sample-app/public/index.html (3 hunks)
  • examples/reactjs/vite/sample-app/index.html (3 hunks)
  • examples/v3-beacon/index.html (4 hunks)
  • examples/v3-legacy-minimum-plugins/index.html (4 hunks)
  • examples/v3-legacy/index.html (4 hunks)
  • examples/v3-minimum-plugins/index.html (4 hunks)
  • examples/v3/index.html (4 hunks)
  • packages/analytics-js/__fixtures__/msw.handlers.ts (1 hunks)
  • packages/analytics-js/__tests__/nativeSdkLoader.js (4 hunks)
  • packages/analytics-js/public/index.html (5 hunks)
  • packages/loading-scripts/rollup.config.mjs (2 hunks)
  • packages/loading-scripts/src/index.ts (2 hunks)
  • packages/sanity-suite/public/v3/index-cdn.html (4 hunks)
  • packages/sanity-suite/public/v3/index-local.html (4 hunks)
  • packages/sanity-suite/public/v3/index-npm-bundled.html (3 hunks)
  • packages/sanity-suite/public/v3/index-npm.html (3 hunks)
  • packages/sanity-suite/public/v3/integrations/index-cdn.html (4 hunks)
  • packages/sanity-suite/public/v3/integrations/index-local.html (4 hunks)
  • packages/sanity-suite/public/v3/integrations/index-npm-bundled.html (3 hunks)
  • packages/sanity-suite/public/v3/integrations/index-npm.html (3 hunks)
  • packages/sanity-suite/public/v3/manualLoadCall/index-cdn.html (4 hunks)
  • packages/sanity-suite/public/v3/manualLoadCall/index-local.html (4 hunks)
  • packages/sanity-suite/public/v3/manualLoadCall/index-npm-bundled.html (3 hunks)
  • packages/sanity-suite/public/v3/manualLoadCall/index-npm.html (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (28)
  • examples/nextjs/hooks/sample-app/src/app/layout.tsx
  • packages/loading-scripts/rollup.config.mjs
  • examples/reactjs/vite/sample-app/index.html
  • packages/analytics-js/fixtures/msw.handlers.ts
  • examples/reactjs/hooks/sample-app/public/index.html
  • examples/nextjs/ts/sample-app/src/app/layout.tsx
  • examples/reactjs/js/sample-app/public/index.html
  • packages/sanity-suite/public/v3/index-npm-bundled.html
  • packages/analytics-js/public/index.html
  • packages/analytics-js/tests/nativeSdkLoader.js
  • examples/v3-minimum-plugins/index.html
  • examples/v3-beacon/index.html
  • packages/loading-scripts/src/index.ts
  • packages/sanity-suite/public/v3/manualLoadCall/index-npm-bundled.html
  • examples/nextjs/page-router/sample-app/src/pages/_document.tsx
  • examples/reactjs/ts/sample-app/public/index.html
  • examples/nextjs/js/sample-app/src/app/layout.js
  • packages/sanity-suite/public/v3/index-local.html
  • packages/sanity-suite/public/v3/index-npm.html
  • examples/integrations/Ninetailed/sample-apps/app-using-v3-cdn/public/index.html
  • packages/sanity-suite/public/v3/integrations/index-local.html
  • examples/v3/index.html
  • examples/angular/sample-app/src/index.html
  • packages/sanity-suite/public/v3/integrations/index-npm.html
  • examples/v3-legacy-minimum-plugins/index.html
  • packages/sanity-suite/public/v3/integrations/index-cdn.html
  • packages/sanity-suite/public/v3/index-cdn.html
  • examples/v3-legacy/index.html
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Bundle size checks
  • GitHub Check: Unit Tests and Lint
  • GitHub Check: Security and code quality checks
🔇 Additional comments (14)
packages/sanity-suite/public/v3/integrations/index-npm-bundled.html (2)

35-35: Version Update: RudderSnippetVersion Bump.
The snippet version has been correctly updated to "3.0.60", which aligns with the PR’s objective of version incrementing.


60-60: Improved Undefined Check in Error Handling.
Replacing the check from void 0 to undefined increases the readability and clarity of the error handling logic. This adjustment is in line with modern JavaScript best practices.

packages/sanity-suite/public/v3/manualLoadCall/index-npm.html (2)

35-35: Updated RudderSnippetVersion
The snippet version is correctly updated to "3.0.60". Ensure that all downstream integrations and documentation reflect this change.


60-60: Enhanced Error Handling Clarity
Changing the check from using void 0 to explicitly comparing against undefined improves code clarity. This makes it immediately understandable that the code verifies the existence of the method before calling apply().

packages/sanity-suite/public/v3/manualLoadCall/index-cdn.html (6)

35-35: Update RudderSnippetVersion for Consistency
The snippet version has been updated from "3.0.58" to "3.0.60", which ensures consistency across the SDK and aligns with the version bump required in the PR objectives.


47-49: Separate SDK URL Components for Clarity
Introducing the distinct variables sdkBaseUrl, sdkVersion, and sdkFileName improves clarity. Customers can now update only the CDN URL while the version and file name remain intact. This aligns perfectly with the PR objectives of removing ambiguity in URL construction.


60-60: Simplify Undefined Check in Error Handling
The error handling logic now checks for undefined instead of using void 0. This change makes the code more readable and adheres to modern JavaScript best practices.


92-98: Robust GlobalThis Polyfill Implementation
The updated polyfill using the getGlobal function now checks for self (for web workers) and window (for browsers) to determine the global object. This ensures better compatibility—especially for older browsers like IE11—by accurately polyfilling globalThis when undefined.


103-107: Conditional Definition of globalThis
By utilizing Object.defineProperty to set globalThis on the global object when it isn’t defined, this code ensures a clean and controlled definition of the global object across environments.


110-110: Dynamic Construction of SDK URL
The script URL is now dynamically constructed by concatenating sdkBaseUrl, sdkVersion, window.rudderAnalyticsBuildType, and sdkFileName. Please verify that this URL structure accurately supports custom domains and maintains the intended versioning behavior.

packages/sanity-suite/public/v3/manualLoadCall/index-local.html (4)

35-35: Update RudderSnippetVersion to "3.0.60"
The snippet version has been correctly bumped from "3.0.58" to "3.0.60" as per the requirements, ensuring consistency across integrations.


47-49: Introduce Explicit SDK URL Variables
Splitting the CDN URL into distinct variables—sdkBaseUrl, sdkVersion, and sdkFileName—improves clarity and makes it easier for customers to update only the necessary parts (e.g., when using custom domains). Please ensure that the placeholder value "__CDN_VERSION_PATH__" for sdkVersion is properly replaced during the build or deployment process.


60-60: Refactor SDK Method Error Handling
The update replacing void 0 with an explicit undefined improves clarity in the condition checking before invoking the SDK’s methods. Double-check that this change does not alter the intended short-circuit behavior in edge cases.


92-107: Enhance Global Object Detection & Polyfill globalThis
The newly defined getGlobal function, along with the use of Object.defineProperty to polyfill globalThis, provides a robust fallback for environments (e.g., IE11) that lack native support. This change will contribute to improved cross-browser compatibility.

Copy link

@ChryssaAliferi ChryssaAliferi left a comment

Choose a reason for hiding this comment

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

🙌

@saikumarrs saikumarrs merged commit 843d944 into develop Feb 19, 2025
11 checks passed
@saikumarrs saikumarrs deleted the fix.loading-snippet-sdk-2942 branch February 19, 2025 09:50
@coderabbitai coderabbitai bot mentioned this pull request Feb 27, 2025
5 tasks
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