Skip to content

[sitecore-jss-react] Preserve form state and interactivity between rerenders#2197

Merged
yavorsk merged 2 commits into
devfrom
feature/JSS-9341
Apr 24, 2026
Merged

[sitecore-jss-react] Preserve form state and interactivity between rerenders#2197
yavorsk merged 2 commits into
devfrom
feature/JSS-9341

Conversation

@yavorsk
Copy link
Copy Markdown
Contributor

@yavorsk yavorsk commented Apr 24, 2026

Description / Motivation

Using dangerouslySetInnerHTML caused scripts to execute only on the initial render. Subsequent re-renders would update the HTML but would not re-trigger executeScripts, breaking form validation and interactive features.
Avoid this by replacing dangerouslySetInnerHTML with setting innerHtml offormRef.
Decoupled logic into two distinct useEffects: one for fetching content and one for injecting HTML/executing scripts.

  • Form scripts now run correctly on every re-render.
  • Form state is now preserved across renders.

Testing Details

  • Unit Test Added
  • Manual Test/Other (Please elaborate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Copy link
Copy Markdown
Collaborator

@illiakovalenko illiakovalenko left a comment

Choose a reason for hiding this comment

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

👍

@yavorsk yavorsk merged commit 0c2f41e into dev Apr 24, 2026
5 checks passed
@yavorsk yavorsk deleted the feature/JSS-9341 branch April 24, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants