Conversation
📝 WalkthroughWalkthroughThis PR modifies build artifact exclusion in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
Before applying any fix, first verify the finding against the current code and
decide whether a code change is actually needed. If the finding is not valid or
no change is required, do not modify code for that item and briefly explain why
it was skipped.
In `@packages/stripe_web/lib/src/widgets/card_field.dart`:
- Around line 88-111: The MutationObserver and initial mount logic are
incorrectly nested inside the if (!widget.dangerouslyUpdateFullCardDetails)
block, so when dangerouslyUpdateFullCardDetails is true the card never mounts;
refactor the build/init path so only the debug/dev.log warning (which checks
controller.details vs CardFieldInputDetails) remains conditional, and move the
MutationObserver creation/observe and the call to _mountCard() out of that
conditional so they always run during initialization (while preserving the
existing _mutationObserver variable and the disconnect logic).
| if (!widget.dangerouslyUpdateFullCardDetails) { | ||
| if (kDebugMode && | ||
| controller.details != | ||
| const CardFieldInputDetails(complete: false)) { | ||
| dev.log('WARNING! Initial card data value has been ignored. \n' | ||
| '$kDebugPCIMessage'); | ||
| } | ||
| }); | ||
| // Use MutationObserver to wait for the DOM element to be inserted, | ||
| // matching the pattern used by PaymentElement. This is necessary | ||
| // because postFrameCallback timing is unreliable on Safari in | ||
| // deployed environments. | ||
| _mutationObserver = web.MutationObserver( | ||
| ((JSArray<web.MutationRecord> entries, web.MutationObserver observer) { | ||
| if (web.document.getElementById('card-element') != null) { | ||
| _mutationObserver?.disconnect(); | ||
| _mountCard(); | ||
| } | ||
| }.toJS), | ||
| ); | ||
| _mutationObserver!.observe( | ||
| web.document, | ||
| web.MutationObserverInit(childList: true, subtree: true), | ||
| ); | ||
| } |
There was a problem hiding this comment.
Card element is never mounted when dangerouslyUpdateFullCardDetails is true.
The entire MutationObserver setup (including the call to _mountCard()) is inside the if (!widget.dangerouslyUpdateFullCardDetails) block. When this flag is true, the card element will never be mounted, causing the field to not render at all.
The mounting logic should execute regardless of this flag; only the debug warning for initial card data should be conditional.
🐛 Proposed fix
void initStripe() {
attachController(controller);
if (!widget.dangerouslyUpdateFullCardDetails) {
if (kDebugMode &&
controller.details !=
const CardFieldInputDetails(complete: false)) {
dev.log('WARNING! Initial card data value has been ignored. \n'
'$kDebugPCIMessage');
}
- // Use MutationObserver to wait for the DOM element to be inserted,
- // matching the pattern used by PaymentElement. This is necessary
- // because postFrameCallback timing is unreliable on Safari in
- // deployed environments.
- _mutationObserver = web.MutationObserver(
- ((JSArray<web.MutationRecord> entries, web.MutationObserver observer) {
- if (web.document.getElementById('card-element') != null) {
- _mutationObserver?.disconnect();
- _mountCard();
- }
- }.toJS),
- );
- _mutationObserver!.observe(
- web.document,
- web.MutationObserverInit(childList: true, subtree: true),
- );
}
+ // Use MutationObserver to wait for the DOM element to be inserted,
+ // matching the pattern used by PaymentElement. This is necessary
+ // because postFrameCallback timing is unreliable on Safari in
+ // deployed environments.
+ _mutationObserver = web.MutationObserver(
+ ((JSArray<web.MutationRecord> entries, web.MutationObserver observer) {
+ if (web.document.getElementById('card-element') != null) {
+ _mutationObserver?.disconnect();
+ _mountCard();
+ }
+ }.toJS),
+ );
+ _mutationObserver!.observe(
+ web.document,
+ web.MutationObserverInit(childList: true, subtree: true),
+ );
}🤖 Prompt for AI Agents
Before applying any fix, first verify the finding against the current code and
decide whether a code change is actually needed. If the finding is not valid or
no change is required, do not modify code for that item and briefly explain why
it was skipped.
In `@packages/stripe_web/lib/src/widgets/card_field.dart` around lines 88 - 111,
The MutationObserver and initial mount logic are incorrectly nested inside the
if (!widget.dangerouslyUpdateFullCardDetails) block, so when
dangerouslyUpdateFullCardDetails is true the card never mounts; refactor the
build/init path so only the debug/dev.log warning (which checks
controller.details vs CardFieldInputDetails) remains conditional, and move the
MutationObserver creation/observe and the call to _mountCard() out of that
conditional so they always run during initialization (while preserving the
existing _mutationObserver variable and the disconnect logic).
Use MutationObserver to wait for the DOM element to be inserted, matching the pattern used by PaymentElement. This is necessary because postFrameCallback timing is unreliable in deployed environments so sometimes the card field would not render.
Summary by CodeRabbit