Skip to content

Conversation

@molly-moen
Copy link
Contributor

@molly-moen molly-moen commented Dec 17, 2025

This updates Web Lab 2 to use the service worker based preview by default. See #69422 and #69557 for details on the previous work to get this set up.

Using this new preview will make running Web Lab 2 locally a little more complex. The reason for this is due to how service workers expect localhost to be set up; namely, not how we do it 😄 Because our localhost isn't viewed as "secure" for service workers, we have to break glass a bit. The easiest way to do this is on Chrome. You can set a flag with chrome://flags/#unsafely-treat-insecure-origin-as-secure (search that in chrome to load the flag settings). I would recommend setting this flag to the following so you can run on either port:

http://localhost-studio.code.org:9000,http://localhost-studio.code.org:3000,http://localtesting.preview.localhost.codeprojects.org:9000,http://localtesting.preview.localhost.codeprojects.org:3000

By default on localhost we use a fixed prefix for the preview url because otherwise you would need to add an exception for every channel id you test. If you want to use the channel id based prefix, use the flag ?weblab2-full-urls=true or ?enableExperiments=weblab2-full-urls (only works on localhost, otherwise we always use the full url).

Another side effect of this issue is drone tests that rely on the preview won't work, because drone runs a "localhost" version of the app. Therefore I've split the web lab 2 UI test into a preview test and a general test, so on drone we at least have a general "it renders" test. The preview test will run on test only now.

I kept the legacy preview available under the flag weblab2-legacy-preview for now, in case there an unexpected issues for users. The only major issue I could see happening is a school firewall blocking the service worker, which could take time to unblock.

Links

Testing story

Tested locally with these changes, and on prod with the previous experiment flag enabled.

Follow up work

After this has been out for a few days and we don't see issues with users, we can remove the legacy flag and the old code. Then I will rename InnerHTMLPreview2 to InnerHTMLPreview. I'll also see if there's any logic in HTMLPreview we can get rid of once we are on one preview.

PR Creation Checklist:

  • Tests provide adequate coverage
  • Privacy impacts have been documented
  • Security impacts have been documented
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Follow-up work items (including potential tech debt) are tracked and linked

@molly-moen molly-moen changed the title Web lab 2 Preview v2 (testing drone) Turn on Web lab 2 Preview v2 by default Dec 17, 2025
@molly-moen molly-moen marked this pull request as ready for review December 17, 2025 21:27
@molly-moen molly-moen requested review from a team and snickell December 17, 2025 21:28
@molly-moen molly-moen removed request for a team and snickell December 18, 2025 17:36
@molly-moen molly-moen marked this pull request as draft December 18, 2025 17:36
@molly-moen
Copy link
Contributor Author

Converting to draft while I resolve an issue with starter images on the new preview

@molly-moen molly-moen marked this pull request as ready for review January 7, 2026 22:16
@molly-moen molly-moen requested review from a team and snickell January 7, 2026 22:16
Copy link
Contributor

@fisher-alice fisher-alice left a comment

Choose a reason for hiding this comment

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

Exciting! Just left a non-blocking suggestion about adding a dcdo flag.

document.addEventListener('DOMContentLoaded', () => {
ReactDOM.render(
useWeblab2PreviewV2 ? <InnerHTMLPreview2 /> : <InnerHTMLPreview />,
useLegacyPreview ? <InnerHTMLPreview /> : <InnerHTMLPreview2 />,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this is being overly cautious, but what do you think of adding a dcdo flag in case there's an issue found that impacts all users?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think given it's a pilot and we have tested it on prod already with multiple machines I don't think we need a dcdo flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good!

// to enable the fixed prefix locally.
// Use the flag ?weblab2-full-urls=true or ?enableExperiments=weblab2-full-urls
// to use the true channel id based url on localhost (this makes it so having multiple tabs with different projects
// open at the same time works correctly).
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice option!

@molly-moen molly-moen merged commit 3452311 into staging Jan 8, 2026
6 checks passed
@molly-moen molly-moen deleted the molly/preview-v2 branch January 8, 2026 17:21
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