Skip to content

fix(code-help): make the SDK snippets runnable - #8145

Merged
talissoncosta merged 2 commits into
mainfrom
fix/onboarding-code-snippets
Jul 29, 2026
Merged

fix(code-help): make the SDK snippets runnable#8145
talissoncosta merged 2 commits into
mainfrom
fix/onboarding-code-snippets

Conversation

@talissoncosta

@talissoncosta talissoncosta commented Jul 28, 2026

Copy link
Copy Markdown
Contributor
  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Follow-up to #8132. The onboarding's Python snippet failed on copy-paste, so I ran every snippet through its real toolchain. Most were broken:

  • Didn't compile: .NET (static on a top-level declaration, and the constructor takes a FlagsmithConfiguration), Go (rune-literal key, GetEnvironmentFlags missing its ctx, no package/main), Next.js (missing paren, <>{...}</>).
  • Didn't run: Python (json.loads with no import), Node (imports a default export the SDK lacks), PHP (undefined $flags, no <?php, install omitted the required PSR-18 client), Flutter (undefined config, baseURI passed to the wrong class), React Native (rendered <div>/<p>, which don't exist in RN), JavaScript (called a function the user doesn't have).
  • Wrong output: Ruby commented with //, .NET with #, iOS printed the literal string false. The Rust and Flutter installs were prose, not commands.

Snippets now print their result, and code blocks get tab-size so Go's tabs don't render 8 columns wide.

codeHelp.INIT takes an optional feature name. The onboarding passes the flag it created, so the snippet stops referencing banner_size, a flag nobody has; the Features page passes nothing and keeps both placeholders as today. Flag names are no longer interpolated into variable names, since a user-chosen name with a space or hyphen broke the JS snippets.

Identity and segment snippets are in #8146.

How did you test this code?

A test covers all 15 init snippets in both shapes (368 unit tests). It needed .js in the Jest transform, with node_modules excluded again; the suite still runs in ~1s.

Then each snippet through its toolchain, in Docker where needed:

Snippet Result
Python, Node.js Executed
Go go build, go run, gofmt-clean
.NET dotnet build succeeded, ran
Java mvn compile succeeded
Rust cargo build, no warnings
PHP php -l, composer, executed
Flutter dart analyze, no issues
React, JavaScript Bundled and loaded in a browser; React renders the flag values
React Native, Next.js (both routers) Parsed
Ruby ruby -c only, no gem installed
curl Executed, clean 404 for a placeholder key
iOS Not tested, needs Xcode

All runs used a placeholder key, so this shows the code is valid and the SDK calls exist, not that a real flag value came back. Java, Rust and Flutter are fragments, compiled inside a minimal wrapper; Go and .NET are now complete programs because their compilers reject fragments.

  • Features page → SDK integration: two placeholder flags as today, plus the fixes
  • Onboarding → Connect your code: every language references only the created flag

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ready Ready Preview, Comment Jul 29, 2026 8:42am
flagsmith-frontend-staging Ready Ready Preview, Comment Jul 29, 2026 8:42am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Jul 29, 2026 8:42am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change passes onboarding feature names directly into SDK snippet generation and adds a dedicated React Native generator. Language templates now initialise clients, retrieve environment flags, and display primary and alternate feature values using consistent fallback rules. React and Next.js templates conditionally subscribe to alternate flags. Onboarding connection state now carries an SDK label through the UI, with Storybook and end-to-end coverage. Jest transforms JavaScript templates, installation commands are updated, and highlighted-code styling gains tab sizing.

Estimated code review effort: 4 (Complex) | ~60 minutes


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

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the front-end Issue related to the React Front End Dashboard label Jul 28, 2026
@github-actions github-actions Bot added the fix label Jul 28, 2026
@talissoncosta
talissoncosta force-pushed the fix/onboarding-code-snippets branch from 003d340 to 112bf20 Compare July 28, 2026 18:21
@github-actions github-actions Bot added fix and removed fix labels Jul 28, 2026
@talissoncosta
talissoncosta force-pushed the fix/onboarding-code-snippets branch from 112bf20 to cfbb0b1 Compare July 28, 2026 19:19
@github-actions github-actions Bot added fix and removed fix labels Jul 28, 2026
@talissoncosta
talissoncosta force-pushed the fix/onboarding-code-snippets branch from cfbb0b1 to a857271 Compare July 28, 2026 19:21
@github-actions github-actions Bot added fix and removed fix labels Jul 28, 2026
@talissoncosta
talissoncosta force-pushed the fix/onboarding-code-snippets branch from a857271 to 466a87f Compare July 28, 2026 19:22
@github-actions github-actions Bot added fix and removed fix labels Jul 28, 2026
@talissoncosta
talissoncosta force-pushed the fix/onboarding-code-snippets branch from 466a87f to 56b7fcf Compare July 28, 2026 19:34
@github-actions github-actions Bot removed the fix label Jul 28, 2026
Python snippet was failing on copy-paste, and the same class of bug
affected most of the others. Each snippet was rendered and read back to confirm
the output.

- Python called json.loads with no import, and would have raised JSONDecodeError
  on a plain string value anyway. It now reads the value directly.
- PHP read $flags without ever defining it.
- Ruby used // for comments, .NET used #.
- Go passed the environment key in single quotes, which is a rune literal.
- JavaScript called myCoolFeature(), which does not exist in the user's app.
- Next.js was missing a closing paren in the App signature, and both routers
  ended in `<>{...}</>`, which does not compile.
- iOS, and 10 traits/create-user templates, used `cond && \`...\`` inside a
  template literal, rendering the string "false" into the snippet whenever the
  URL is not custom, i.e. on SaaS.

The second flag is now optional. codeHelp.INIT takes a feature name, and the
onboarding passes the flag it just created so the snippet references that one
flag rather than a placeholder nobody has. The Features page passes nothing and
keeps both placeholders as before. This also lets the onboarding drop its
string-replacement of the placeholder name.

Snippets no longer interpolate the flag name into variable names or dot access,
since the onboarding name is user-chosen and a space or hyphen made the JS
snippets a syntax error.

Adds a test over all 14 init snippets, covering both the one-flag and two-flag
shapes. It needed `.js` transforming in Jest, scoped so node_modules stays
untransformed; the full suite still runs in ~1s.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-8145 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-8145 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-8145 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-8145 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-8145 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-8145 Finished ✅ Results

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #18826 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  36.3 seconds
commit  b4c5c38
info  🔄 Run: #18826 (attempt 1)

🗂️ Previous results
✅ private-cloud · depot-ubuntu-latest-16 — run #18826 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  17.8 seconds
commit  b4c5c38
info  🔄 Run: #18826 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #18826 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  38.2 seconds
commit  b4c5c38
info  🔄 Run: #18826 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #18826 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  39.3 seconds
commit  b4c5c38
info  🔄 Run: #18826 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-16 — run #18814 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  31.8 seconds
commit  3bf6069
info  🔄 Run: #18814 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #18814 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  45.6 seconds
commit  3bf6069
info  🔄 Run: #18814 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #18814 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  22 passed
skipped  1 skipped

Details

stats  23 tests across 18 suites
duration  1 minute, 22 seconds
commit  3bf6069
info  🔄 Run: #18814 (attempt 1)

Skipped tests

firefox › tests/onboarding-tests.pw.ts › Onboarding › New user connects via the single-page onboarding flow @oss

✅ oss · depot-ubuntu-latest-16 — run #18814 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  34.4 seconds
commit  3bf6069
info  🔄 Run: #18814 (attempt 1)

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Visual Regression

19 screenshots compared. See report for details.
View full report

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 7


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 742c5ffe-76cf-49bb-a119-efdc2ca52f2b

📥 Commits

Reviewing files that changed from the base of the PR and between b8073b9 and 3bf6069.

📒 Files selected for processing (23)
  • frontend/common/code-help/__tests__/init-snippets.test.ts
  • frontend/common/code-help/init/init-dotnet.js
  • frontend/common/code-help/init/init-flutter.js
  • frontend/common/code-help/init/init-go.js
  • frontend/common/code-help/init/init-ios.js
  • frontend/common/code-help/init/init-java.js
  • frontend/common/code-help/init/init-js.js
  • frontend/common/code-help/init/init-next-app-router.js
  • frontend/common/code-help/init/init-next-pages-router.js
  • frontend/common/code-help/init/init-node.js
  • frontend/common/code-help/init/init-php.js
  • frontend/common/code-help/init/init-python.js
  • frontend/common/code-help/init/init-react-native.js
  • frontend/common/code-help/init/init-react.js
  • frontend/common/code-help/init/init-ruby.js
  • frontend/common/code-help/init/init-rust.js
  • frontend/common/code-help/install/install-flutter.js
  • frontend/common/code-help/install/install-php.js
  • frontend/common/code-help/install/install-rust.js
  • frontend/common/constants.ts
  • frontend/jest.config.js
  • frontend/web/components/pages/onboarding/OnboardingConnectPanel/sdkSnippets.ts
  • frontend/web/styles/3rdParty/_hljs.scss

Comment thread frontend/common/code-help/__tests__/init-snippets.test.ts
Comment thread frontend/common/code-help/init/init-js.js
Comment thread frontend/common/code-help/init/init-react-native.js
Comment thread frontend/common/code-help/init/init-react.js
Comment thread frontend/common/code-help/init/init-rust.js
Comment thread frontend/common/constants.ts
Comment thread frontend/web/styles/3rdParty/_hljs.scss
)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1bcb1b73-a5fe-4e19-a732-c633bf9f2894

📥 Commits

Reviewing files that changed from the base of the PR and between 3bf6069 and b4c5c38.

📒 Files selected for processing (5)
  • frontend/documentation/pages/onboarding/OnboardingTerminal.stories.tsx
  • frontend/e2e/tests/onboarding-tests.pw.ts
  • frontend/web/components/pages/onboarding/OnboardingFlow/OnboardingFlow.tsx
  • frontend/web/components/pages/onboarding/OnboardingTerminal/OnboardingTerminal.tsx
  • frontend/web/components/pages/onboarding/hooks/useOnboardingConnection.ts

@kyle-ssg

kyle-ssg commented Jul 29, 2026

Copy link
Copy Markdown
Member

@talissoncosta great job, I've gone through and run validation of every language against sample data and it all passes. I think that's as good as a review I can give, one thing's for sure is that it's an improvement - I think we should go ahead and merge this

@talissoncosta
talissoncosta merged commit 238babf into main Jul 29, 2026
29 checks passed
@talissoncosta
talissoncosta deleted the fix/onboarding-code-snippets branch July 29, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants