Skip to content

Update to fix CCP locale switching#1342

Open
cocomarine wants to merge 8 commits intomainfrom
hj/testing-locale-switch-3
Open

Update to fix CCP locale switching#1342
cocomarine wants to merge 8 commits intomainfrom
hj/testing-locale-switch-3

Conversation

@cocomarine
Copy link
Contributor

@cocomarine cocomarine commented Feb 25, 2026

Changes

Locale switching fix

Initial load problem fix

  • Before: when an editor page with locales other than en was first loaded in CCP, it rendered en page rather than the locale page (editor-standalone was fine)
  • Updated to make sure initial attributes like locale are passed to React by reading them from the DOM in reactProps() of web-component.js
    • This is so that the first render uses the host's value even when attributeChangedCallback hasn't been run yet

Copilot AI review requested due to automatic review settings February 25, 2026 14:51
@cocomarine cocomarine temporarily deployed to previews/1342/merge February 25, 2026 14:52 — with GitHub Actions Inactive
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the project-loading hook to make localStorage cache usage dependent on the active i18n locale, aiming to prevent incorrect cached content from being loaded after CCP locale switching.

Changes:

  • Adds a locale match check (cachedProject?._cachedLocale === i18n.language) before loading a cached project.
  • Simplifies the cache eligibility logic into a single shouldUseCache condition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cocomarine cocomarine temporarily deployed to previews/1342/merge February 25, 2026 15:21 — with GitHub Actions Inactive
@cocomarine cocomarine temporarily deployed to previews/1342/merge February 25, 2026 15:43 — with GitHub Actions Inactive
@cocomarine cocomarine temporarily deployed to previews/1342/merge February 26, 2026 08:10 — with GitHub Actions Inactive
@zetter-rpf
Copy link
Contributor

This is a temporary fix as it effectively disabled caching.

For my understanding, do you mean this disables the project caching when you change locale? Or is it more than that?

Copy link
Contributor

@zetter-rpf zetter-rpf left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, the approach looks good. Let me know when you have fixed the tests and I can re-review.

It would be good to have at least one new test for the updated behaviour of useProject

@cocomarine cocomarine temporarily deployed to previews/1342/merge February 26, 2026 16:43 — with GitHub Actions Inactive
@cocomarine cocomarine temporarily deployed to previews/1342/merge March 2, 2026 08:31 — with GitHub Actions Inactive
@cocomarine
Copy link
Contributor Author

This is a temporary fix as it effectively disabled caching.

For my understanding, do you mean this disables the project caching when you change locale? Or is it more than that?

Yes, I tried to change as little as possible from the existing code for the effect of disabling caching.

@cocomarine cocomarine temporarily deployed to previews/1342/merge March 2, 2026 08:54 — with GitHub Actions Inactive
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The GitHub diff looks odd for this file; basically, I commented out caching-related tests and added these two tests:

describe("When not embedded", () => {
...
 // Tests for the temporarily disabled cache functionality
  test("does not use cache even with loadCache true and matching cache in localStorage", async () => {
    syncProject.mockImplementation(jest.fn((_) => loadProject));
    localStorage.setItem("hello-world-project", JSON.stringify(cachedProject));
    renderHook(
      () =>
        useProject({
          projectIdentifier: "hello-world-project",
          accessToken,
          loadCache: true,
          reactAppApiEndpoint,
        }),
      { wrapper },
    );
    expect(setProject).not.toHaveBeenCalledWith(cachedProject);
    expect(syncProject).toHaveBeenCalledWith("load");
  });

  test("does not use cache when cache locale does not match effectiveLocale and loads from server", async () => {
    syncProject.mockImplementation(jest.fn((_) => loadProject));
    const cachedWrongLocale = { ...cachedProject, locale: "en-GB" };
    localStorage.setItem(
      cachedWrongLocale.identifier,
      JSON.stringify(cachedWrongLocale),
    );
    renderHook(
      () =>
        useProject({
          projectIdentifier: cachedWrongLocale.identifier,
          loadCache: true,
          accessToken,
          reactAppApiEndpoint,
        }),
      { wrapper },
    );
    expect(setProject).not.toHaveBeenCalledWith(cachedWrongLocale);
    expect(syncProject).toHaveBeenCalledWith("load");
    await waitFor(() =>
      expect(loadProject).toHaveBeenCalledWith({
        identifier: cachedWrongLocale.identifier,
        locale: "ja-JP",
        accessToken,
        reactAppApiEndpoint,
      }),
    );
  });

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