fix: use deep comparison for launch params to prevent spurious warning#142
Draft
behnam-oneschema wants to merge 1 commit intomainfrom
Draft
fix: use deep comparison for launch params to prevent spurious warning#142behnam-oneschema wants to merge 1 commit intomainfrom
behnam-oneschema wants to merge 1 commit intomainfrom
Conversation
The `params` object created via rest destructuring (`...rest`) gets a new reference on every render, causing the 'already launched' warning useEffect to fire on every re-render — even when no param values actually changed. Replace referential equality with JSON.stringify-based deep comparison using a useRef to track the previous serialized params value. The warning now only fires when param values have genuinely changed after the importer has already launched. Closes #137 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Original prompt from Behnam 🧑💻
|
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Fixes #137. The
OneSchemaImporterReact component logs a spurious "already launched" warning on every re-render after the importer has launched, even when no launch params have actually changed.Root cause:
paramsis created via...restdestructuring in the function signature, producing a new object reference on every render. TheuseEffectdependency array used this unstable reference, so the effect (and the warning) fired on every render cycle.Fix: Replace referential equality with
JSON.stringify-based deep comparison. AuseReftracks the previous serialized params, and the warning only fires when param values have genuinely changed. The dependency array usesJSON.stringify(params)so the effect itself is also skipped when values are stable.Review & Testing Checklist for Human
JSON.stringifyis adequate for allOneSchemaLaunchParamOptionsfields — confirm none contain functions,undefinedvalues that matter, or circular references that would break serializationprevParamsRef.current !== undefined) correctly suppresses the warning on initial mount (we don't want a warning before params have ever "changed")<OneSchemaImporter>withisOpen={true}, trigger a parent re-render (e.g. unrelated state change), and confirm the console warning no longer appears. Then actually change a launch param (e.g.userJwt) and confirm the warning does appear.Notes
JSON.stringifyis used instead of a third-party deep-compare library.eslint-disable-next-line react-hooks/exhaustive-depsis intentional: the dep array uses a computedJSON.stringify(params)expression rather than the rawparamsobject, which the lint rule doesn't understand.Link to Devin session: https://app.devin.ai/sessions/d9dbde3b76454bd6aa82a610c90d6776
Requested by: @behnam-oneschema