fix: prevent frozen format from crashing CustomMetricModal on reopen#22065
Open
charliedowler wants to merge 1 commit intomainfrom
Open
fix: prevent frozen format from crashing CustomMetricModal on reopen#22065charliedowler wants to merge 1 commit intomainfrom
charliedowler wants to merge 1 commit intomainfrom
Conversation
Failing test demonstrating that form.values.format is frozen in-place when passed by reference to prepareCustomMetricData and the returned metric is deep-frozen by Immer (Redux Toolkit). On the next modal open, @mantine/form's klona-based setFieldValue throws: TypeError: Cannot assign to read only property 'type' Fix to follow in next commit. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🧪 Test Selection✅ Tests that will run
⏭️ Tests skipped (no relevant file changes detected)
|
|
Your preview environment pr-22065 has been deployed. Preview environment endpoints are available at: |
Preview Environment🌐 URL: https://lightdash-preview-pr-22065.lightdash.okteto.dev 📋 Logs: View in GCP Console 🔧 SSH: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
When a user creates or edits a custom metric in the Explorer's CustomMetricModal and then reopens it to change the format type, React throws:
This crashes the modal via the ErrorBoundary. Sentry: LIGHTDASH-FRONTEND-G3 / Linear: PROD-2067.
Expected
The format type selector in CustomMetricModal works correctly across multiple open/close cycles.
Root cause
CustomMetricModal/index.tsxpassesform.values.formatby reference asformatOptions: formattoprepareCustomMetricData. The returned metric is dispatched to Redux, and Redux Toolkit (Immer) deep-freezes the action payload in-place — which, through the shared reference, also freezes the form's internalformatobject.On the next modal open, when the user changes the format type,
@mantine/formcallsklona(values)internally (viasetFieldValue).klona/fullpreserves non-writable property descriptors from frozen objects. The subsequentcloned.format.type = newValueassignment then throwsTypeError: Cannot assign to read only property 'type'in strict mode (all ESM/React code runs strict).This is identical to the bug fixed in
FormatModal(seeFormatModal/index.tsx:46-49).Reproduction
Failing test:
packages/frontend/src/components/Explorer/CustomMetricModal/utils/index.test.tsThe third test (
format passed to prepareCustomMetricData is isolated from Immer freeze) passesformatby reference (simulating the buggy modal code), deep-freezes the result (simulating Immer dispatch), and asserts the originalformatis not frozen. This assertion fails — proving the reference chain propagates the freeze.Evidence (before)
formatIS frozen (true) when it should not be (false).Fix
Pending — see follow-up commit.