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: don't break personal dashboard charts if the flag is called . #8807

Merged

Conversation

thomasheartman
Copy link
Contributor

@thomasheartman thomasheartman commented Nov 20, 2024

This PR fixes an issue where the personal dashboard would fail to render if the flag was called . (Curiously, it was not an issue with ..; probably because they end up accessing different URLs).

I've taken the very pragmatic approach here of saying "right, we know that . and .. cause issues, let's just not even try to fetch data for them".

The option, of course, is to bake in more error handling in the components, but due to how we've got hooks depending on each other, it's a bit of a rabbit hole to go down. I think this is a good compromise for now.

So now, you'll get this instead:
image

I've also gone and updated the text for when we get a metrics fetching error, because this probably isn't due to the flag name anymore. If it is, we want to know.

Copy link

vercel bot commented Nov 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 1:17pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Nov 20, 2024 1:17pm

Copy link
Contributor

github-actions bot commented Nov 20, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

@@ -97,7 +97,7 @@ const EmptyFlagMetricsChart = () => {
const useMetricsEnvironments = (project: string, flagName: string) => {
const [environment, setEnvironment] = useState<string | null>(null);
const { feature } = useFeature(project, flagName);
const activeEnvironments = feature.environments.map((env) => ({
const activeEnvironments = (feature?.environments ?? []).map((env) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the return type of useFeature lying to us? It would indicate the defensive technique is not needed looking at the useFeature return type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good point. It's both lying and we're abusing it.

First, it's wrapping an http request. This means we might not have the data immediately, but we don't wait. Also, there may not be any data there (we might get an error), but we don't handle that (did someone say union types?).

But second, the useFeature hook returns the deprecated IFeatureToggle interface. If you check that interface, you'll find that environments is always present. But if you compare it to the FeatureSchema which supersedes it, you'll see that environments is optional (yikes!).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we should fix the source of truth (the useFeature hook type) so that we don't have to catch those mistakes at runtime

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aye. I'll make a follow-up PR to gauge how much work that'd be.

@thomasheartman thomasheartman merged commit d661096 into main Nov 20, 2024
10 of 11 checks passed
@thomasheartman thomasheartman deleted the 1-3132/don't-break-charts-if-flag-can't-be-accessed branch November 20, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants