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

[NV-3735]: Improve launch darkly #5517

Merged
merged 25 commits into from
May 14, 2024
Merged

[NV-3735]: Improve launch darkly #5517

merged 25 commits into from
May 14, 2024

Conversation

antonjoel82
Copy link
Contributor

@antonjoel82 antonjoel82 commented May 7, 2024

What changed? Why was the change needed?

  • Use async LaunchDarkly initialization, but ensure it works with self-hosted
  • Why? Conditional routing (enabling routes based on feature flags) for Information Architecture is inconsistent, and causes issues with certain routes
  • Resolves NV-3735

Special notes for your reviewer

  • Did we account properly for self-hosted?

Repro

Basic

  1. Check-out the branch improve-launch-darkly
  2. Start everything normally -- upon loading, you should briefly see a reddish loader in the center of the page
  3. Open a new tab and navigate to http://localhost:4200/settings/profile?view=password
  4. You should see the loader again, but will go directly the the User Profile with the sidebar open

Old route hidden behind feature flag

  1. Navigate to http://localhost:4200/brand
  2. The loader should appear, and you should be directed to Workflows

Check non-auth route

  1. Log-out
  2. Everything should load correctly.
  3. Log-in
  4. The loader should appear and the app should then load

Self-hosted

  1. In your local web/.env.local file (or whichever one you're using for local dev), comment out REACT_APP_LAUNCH_DARKLY_CLIENT_SIDE_ID
  2. Start the app
  3. Open the browser tools to the Network tab
  4. The app should load correctly without the loader, but everything will be based on env variables
  5. Filter network requests with launchd and nothing should appear

Copy link

linear bot commented May 7, 2024

Copy link

netlify bot commented May 7, 2024

Deploy Preview for novu-design ready!

Name Link
🔨 Latest commit 80ee88d
🔍 Latest deploy log https://app.netlify.com/sites/novu-design/deploys/663a69422242c9000879c7a9
😎 Deploy Preview https://deploy-preview-5517--novu-design.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented May 7, 2024

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit f155b3d
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/6642b3e49efd0f000824f047
😎 Deploy Preview https://deploy-preview-5517--dev-web-novu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented May 7, 2024

Deploy Preview for novu-design ready!

Name Link
🔨 Latest commit f155b3d
🔍 Latest deploy log https://app.netlify.com/sites/novu-design/deploys/6642b3e412f45b0008afc1d3
😎 Deploy Preview https://deploy-preview-5517--novu-design.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

<Route path="" element={<BrandingForm />} />
<Route path="layouts" element={<LayoutsListPage />} />
</Route>
{!isInformationArchitectureEnabled && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒 note (non-blocking): Fix for information architecture -- previously didn't work due to LD‏

</SegmentProvider>
);
};

export default Sentry.withProfiler(
withLDProvider({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒 note (non-blocking): Moved LD provider to its own file in shared-web with logic‏

Copy link
Contributor

Choose a reason for hiding this comment

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

question: why move to shared-web?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of our other similar providers are there, and many of the related behaviors / imports (i.e. useFeatureFlags) are there, so it seemed best IMO

Copy link
Contributor

Choose a reason for hiding this comment

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

🤓 nitpick (non-blocking): I suggest keeping it closer to the source of the web app unless we are sure it would be reused. Otherwise, we might end up with a landfill.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @LetItRock. I feel that we might be overusing shared packages on some occasions. Other than that, great choice to split it into a separate component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, thanks for the feedback! Updated

@antonjoel82 antonjoel82 marked this pull request as ready for review May 7, 2024 18:47
@antonjoel82 antonjoel82 requested a review from a team May 7, 2024 18:47
const { [key]: featureFlag } = useFlags();
/** We knowingly break the rule of hooks here to avoid making any LaunchDarkly calls when it is disabled */
// eslint-disable-next-line
const flagValue = checkShouldUseLaunchDarkly() ? useFlags()[key] : undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒 note (non-blocking): Breaks the rule of hooks, but should be okay since it's done via a static check.‏

const ldClient = useLDClient();

useEffect(() => {
if (!organization?._id) {
if (!checkShouldUseLaunchDarkly() || !organization?._id) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒 note (non-blocking): The client should never be defined anyway, but just as an extra fail-safe‏


useEffect(() => {
// no need to fetch if LD is disabled or there isn't an org to query against
if (!checkShouldUseLaunchDarkly() || !currentOrganization) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗒 note (non-blocking): Avoids any LD calls for initializing the provider‏

@antonjoel82 antonjoel82 requested a review from scopsy May 7, 2024 19:47
Comment on lines 48 to 50
kind: 'organization',
key: currentOrganization._id,
name: currentOrganization.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

question: If I understand this correctly, this will prevent us from having feature flags on the Onboarding and Signup pages right?

What if we still load launchdarkly in those pages but without the "context" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll investigate further. It definitely introduces some complexity, since they require fundamentally different things. Additionally, we're not handling this properly at the moment

Copy link
Contributor

@LetItRock LetItRock left a comment

Choose a reason for hiding this comment

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

issue: blockers: sign up process and reset password are not working for me

Screen.Recording.2024-05-08.at.00.29.23.mov

Please make sure to run all e2e tests with this PR.

libs/shared-web/src/hooks/useAuthController.ts Outdated Show resolved Hide resolved
</SegmentProvider>
);
};

export default Sentry.withProfiler(
withLDProvider({
Copy link
Contributor

Choose a reason for hiding this comment

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

question: why move to shared-web?

libs/shared-web/src/utils/checkShouldUseLaunchDarkly.ts Outdated Show resolved Hide resolved
libs/shared-web/src/providers/LaunchDarklyProvider.tsx Outdated Show resolved Hide resolved
libs/shared-web/src/providers/LaunchDarklyProvider.tsx Outdated Show resolved Hide resolved
libs/shared-web/src/providers/LaunchDarklyProvider.tsx Outdated Show resolved Hide resolved
@@ -49,6 +49,7 @@ import { useSettingsRoutes } from './SettingsRoutes';

export const AppRoutes = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

🗒 note (non-blocking): the /auth/application is not a protected route 😨

@antonjoel82
Copy link
Contributor Author

issue: blockers: sign up process and reset password are not working for me

Screen.Recording.2024-05-08.at.00.29.23.mov
Please make sure to run all e2e tests with this PR.

Great catch, thanks! This whole non-automated automated tests is beating me 🙃

</SegmentProvider>
);
};

export default Sentry.withProfiler(
withLDProvider({
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @LetItRock. I feel that we might be overusing shared packages on some occasions. Other than that, great choice to split it into a separate component.

libs/shared-web/src/hooks/useAuthController.ts Outdated Show resolved Hide resolved
@antonjoel82
Copy link
Contributor Author

Unfortunately, I am encountering some flakiness with tests, but I have verified manually that the behavior works. After talking with Sok this morning, we don't believe it's worth blocking on them since we'll be replacing them soon. Planning to merge this tomorrow morning after deployment breakfast

@antonjoel82 antonjoel82 merged commit 49600bf into next May 14, 2024
34 of 36 checks passed
@antonjoel82 antonjoel82 deleted the improve-launch-darkly branch May 14, 2024 14:49
github-actions bot pushed a commit that referenced this pull request May 16, 2024
Use async LaunchDarkly initialization, but ensure it works with self-hosted

Why? Conditional routing (enabling routes based on feature flags) for Information Architecture is inconsistent, and causes issues with certain routes

Resolves NV-3735
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants