diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b056007e..5343154ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased +### Added + +- Ability for host page to force web component into its loading state (#1272) + ## [0.34.0] - 2025-11-17 ### Added diff --git a/src/containers/WebComponentLoader.jsx b/src/containers/WebComponentLoader.jsx index c0a63fb64..22df5d049 100644 --- a/src/containers/WebComponentLoader.jsx +++ b/src/containers/WebComponentLoader.jsx @@ -41,6 +41,7 @@ const WebComponentLoader = (props) => { hostStyles, // Pass in styles from the host identifier, instructions, + isLoading = false, theme, loadRemixDisabled = false, locale = "en", @@ -251,7 +252,9 @@ const WebComponentLoader = (props) => { ); - if (loading === "success") { + if (isLoading) { + return renderLoadingState(); + } else if (loading === "success") { return renderSuccessState(); } else if (["idle", "failed"].includes(loading)) { return renderFailedState(); diff --git a/src/containers/WebComponentLoader.test.js b/src/containers/WebComponentLoader.test.js index 6aeedc841..297b8942f 100644 --- a/src/containers/WebComponentLoader.test.js +++ b/src/containers/WebComponentLoader.test.js @@ -1,4 +1,4 @@ -import { render, act } from "@testing-library/react"; +import { render, act, screen } from "@testing-library/react"; import React from "react"; import { Provider } from "react-redux"; import configureStore from "redux-mock-store"; @@ -665,3 +665,39 @@ describe("When user is in state", () => { }); }); }); + +describe("When isLoading prop is used", () => { + beforeEach(() => { + const middlewares = []; + const mockStore = configureStore(middlewares); + const initialState = { + editor: { + loading: "success", + project: { + components: [], + }, + openFiles: [], + focussedFileIndices: [], + hasShownSavePrompt: false, + remixLoadFailed: false, + justLoaded: false, + saveTriggered: false, + }, + instructions: {}, + auth: {}, + }; + store = mockStore(initialState); + cookies = new Cookies(); + }); + + test("it respects isLoading prop when rendering", () => { + render( + + + + + , + ); + expect(screen.queryByText("webComponent.loading")).toBeInTheDocument(); + }); +}); diff --git a/src/web-component.js b/src/web-component.js index 345502510..cbdd6dbdd 100644 --- a/src/web-component.js +++ b/src/web-component.js @@ -57,6 +57,7 @@ class WebComponent extends HTMLElement { "host_styles", "identifier", "instructions", + "is_loading", "load_remix_disabled", "locale", "output_only", @@ -83,6 +84,7 @@ class WebComponent extends HTMLElement { [ "embedded", "editable_instructions", + "is_loading", "load_remix_disabled", "output_only", "output_split_view",