fix: a.trim is not a function#3286
Conversation
|
Hi @DSingh0304, could you add a test to fix this issue? |
Yes sure I will.. |
The fix is defensive:
However, if you'd like me to add a test, I can create an e2e test that mocks the API response to simulate corrupted data reaching the frontend. This would demonstrate that the components handle invalid data gracefully, though it would deviate from the existing test pattern where all tests use real API calls for creation and deletion. |
|
Hi everyone Hate to nag but is there any chance of progressing this change? |
|
Hi @DSingh0304, could you please take a look at the reproduction steps in the original issue? It seems that @eccles suggested calling the admin API to create this error data. |
Hi @Baoyuantop, thanks for the clarification! You're right. I misunderstood the scenario earlier. The vars data in the original issue is completely valid APISIX data, not corrupted data. The issue is that it was created via the Admin API, and the dashboard UI couldn't display it properly. I'll add an E2E test |
|
Hey @Baoyuantop I have added the test... |
There was a problem hiding this comment.
Pull request overview
Fixes a runtime crash (a.trim is not a function) in the dashboard route detail view by hardening form components against unexpected non-string values, and adds an E2E regression test covering routes created with vars via the Admin API (issue #3276).
Changes:
- Add defensive normalization in
FormItemTagsInputto avoid passing non-strings into MantineTagsInput. - Add defensive guard in
FormItemLabelsto only process plain-object label values. - Add Playwright E2E test to ensure viewing a route created with
varsdoes not crash.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/components/form/TagInput.tsx | Adds value sanitization before rendering Mantine TagsInput to prevent .trim() runtime crashes. |
| src/components/form/Labels.tsx | Adds a guard to avoid treating non-object/array values as label maps. |
| e2e/tests/routes.vars-admin-api.spec.ts | New E2E test that creates a route with vars via Admin API and validates the detail view loads. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/components/form/TagInput.tsx:68
{...restProps}is spread after the component’s controlledvalue/onChange, so any caller-providedvalueoronChangeinrestPropswill override the react-hook-form wiring (and bypass the new defensive sanitization). Consider omittingvalue/onChange(and related controlled props) from the public prop type and/or moving{...restProps}before the explicitvalue/onChangeprops so the wrapper remains the source of truth.
<TagsInput
value={tagsInputValue}
error={fieldState.error?.message}
onChange={(value) => {
const val = to ? value.map(to) : value;
fOnChange(val);
restProps?.onChange?.(value);
}}
comboboxProps={{ shadow: 'md' }}
acceptValueOnBlur
{...restField}
{...restProps}
/>
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Hi @Baoyuantop I have addressed the comments by copilot.. |
|
I will fix this so that it passes the e2e test. |
|
Hi @DSingh0304, please fix the failed test |
Yes sir I will fix it asap. |
|
Hey @Baoyuantop I have resolved the issue which was causing the CI failure can you please run the workflow again. |
Baoyuantop
left a comment
There was a problem hiding this comment.
The fix direction (defensive filtering of non-string values in TagsInput) is correct, but there are a few issues to address:
-
Unrelated changes: The large diffs in
routeTree.gen.tsandapisix_conf.ymlare unrelated to this bug fix. Please revert them and handle separately if needed. -
CI status: The current
mergeable_stateis unstable. Please ensure the latest commit passes all required checks. -
Silent data filtering risk: TagInput silently drops non-string items, which could cause the UI to show fewer values than actually exist. Suggestions:
- At minimum, add a test to document this as expected behavior
- Better approach: add an observable warning (log or UI-level) when filtering occurs
Please address these items for re-review.
I will go through the comments and address each of them by today. |
…values and add a dedicated e2e test.
…debugging artifacts.
|
@Baoyuantop I have fixed the lint errors and addressed the comments. |
31cb1e7 to
fbd3cfe
Compare
|
@Baoyuantop All the tests pass and the changes suggested by you are also implemented. |
Why submit this pull request?
What changes will this PR take into?
This PR fixes a runtime error
"a.trim is not a function"that occurs when viewing a route with avarsfield in the detail page.The issue was caused by the TagsInput component (from Mantine) receiving non-string values (arrays) in some edge cases. The Mantine TagsInput internally calls
.trim()on each value, which fails when the value is not a string.Changes made:
Related issues
fix #3276
Checklist: