Skip to content

fix: call onChangeCallback when live_preview parameter is present in URL#363

Merged
faraazb merged 5 commits intodevelop_v3from
VE-5279-onchange-when-live-preview-parameter-is-present
Mar 17, 2025
Merged

fix: call onChangeCallback when live_preview parameter is present in URL#363
faraazb merged 5 commits intodevelop_v3from
VE-5279-onchange-when-live-preview-parameter-is-present

Conversation

@faraazb
Copy link
Copy Markdown
Contributor

@faraazb faraazb commented Feb 20, 2025

  • Visual Builder doesn't send client-data-send on site load, this leads to
    the site not making any calls to the preview service which is required
    for the subsequent entry PATCH requests to work correctly.
  • onChangeCallback is called when either skipInitialRender is false or
    when live_preview search parameter is present in the URL.
  • Since Visual Builder provides these values through the search parameter, the site makes entry GET calls to the preview service. Since live preview doesn't provide these params in non-SSR modes, it will continue to work the same.

Visual Builder doesn't send client-data-send on site load, this leads to
the site not making any calls to the preview service which is required
for the subsequent entry PATCH requests to work correctly.
onChangeCallback is called when either skipInitialRender is false or
when live_preview search parameter is present in the URL. Since Visual
Builder provides these values through the search parameter, the site
makes entry GET calls to the preview service. Since live preview doesn't
provide these params in non-SSR modes, it will continue to work the
same.
@faraazb faraazb requested a review from a team as a code owner February 20, 2025 09:04
@faraazb faraazb requested review from KANE-99, contentstackMridul and hiteshshetty-dev and removed request for a team February 20, 2025 09:04
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 20, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 80.8% 6697 / 8288
🔵 Statements 80.8% 6697 / 8288
🔵 Functions 75.3% 244 / 324
🔵 Branches 85.15% 843 / 990
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/preview/contentstack-live-preview-HOC.ts 93.18% 83.33% 100% 93.18% 75-76, 158, 239-244
Generated in workflow #326 for commit 269b852 by the Vitest Coverage Report Action

@faraazb
Copy link
Copy Markdown
Contributor Author

faraazb commented Feb 20, 2025

This may be a problem in Preview, as they send the client-data-send on initial load. And they also have live_preview in search parameters. This will lead to onChangeCallback being called twice.

@faraazb
Copy link
Copy Markdown
Contributor Author

faraazb commented Feb 25, 2025

I have made some additions which ensure that onChange is only called once on site load.

Base automatically changed from develop_v3 to stage_v3 March 4, 2025 06:14
@faraazb faraazb force-pushed the VE-5279-onchange-when-live-preview-parameter-is-present branch from a3ddc4e to f516301 Compare March 6, 2025 11:29
Base automatically changed from stage_v3 to main March 7, 2025 09:25
Avoid calling onLiveEdit in apps other than builder as it can lead to
multiple calls in Timeline and LP. Resolving this issue would then
require storing some state to ensure the callback is only called from
one code location on the first load which then has the posssibiliy of
breaking setups that rely on the behaviour of the callback being called
multiple times.
@faraazb faraazb force-pushed the VE-5279-onchange-when-live-preview-parameter-is-present branch from f516301 to 98562c7 Compare March 10, 2025 12:34
Copy link
Copy Markdown

@KANE-99 KANE-99 left a comment

Choose a reason for hiding this comment

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

LGTM

@faraazb faraazb changed the base branch from main to develop_v3 March 12, 2025 12:49
@faraazb
Copy link
Copy Markdown
Contributor Author

faraazb commented Mar 12, 2025

The failing unit tests are being removed in another PR and some other tests are being added in its place. We can safely ignore them for now.

@faraazb faraazb force-pushed the VE-5279-onchange-when-live-preview-parameter-is-present branch from c9518d5 to 269b852 Compare March 17, 2025 05:32
@faraazb faraazb merged commit 73e46ae into develop_v3 Mar 17, 2025
7 checks passed
@faraazb faraazb deleted the VE-5279-onchange-when-live-preview-parameter-is-present branch March 17, 2025 08:52
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.

3 participants