Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sandpack service worker #8481

Merged
merged 15 commits into from
Jul 9, 2024
Merged

feat: sandpack service worker #8481

merged 15 commits into from
Jul 9, 2024

Conversation

danilowoz
Copy link
Member

@danilowoz danilowoz commented Jun 20, 2024

No description provided.

Copy link

codesandbox bot commented Jun 20, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

*/
if (
parsedUrl.origin !== self.location.origin ||
!parsedUrl.pathname.startsWith('/public')
Copy link
Member Author

Choose a reason for hiding this comment

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

@DeMoorJasper and @CompuIves, one of the essential parts of the service worker is to intercept requests only made by the sandbox in the iframe and ignore all other requests, like static files by the bundler.

However, I'm struggling to find an efficient way to ignore bundler requests from among the ones I want to catch. For example, the bundler requests files from static/**/* and from root, which makes it hard to check each file should be caught by the SW. For now, as a temporary solution, I'm considering all files coming from /public to belong to the sandbox and should be intercepted, while all others are ignored.

Ideally, we should put all bundler static files inside another unique folder, like __csb_static, then we can easily ignore everything coming from this folder. But the webpack configuration is so overwhelming, and I don't know if it can cause side effects in regular sandboxes.

Copy link
Member

@DeMoorJasper DeMoorJasper Jul 4, 2024

Choose a reason for hiding this comment

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

I also think putting all sandpack related files under __csb_static would make sense, I'm not sure where we stand with completely sunsetting v1, that would make things a lot easier as than we can probably remove 90% of this repo and significantly simplify the webpack config.

The temp solution makes sense to me though

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I've been trying to tweak the webpack to bundle everything inside __csb_static, but this seems a massive work, and I don't think we should do it right (too many files to change and check). Once we validate this Service Worker solution and after deprecating the legacy editor, I will be more confident about making these changes. So, for now, let's go for the temp solution (restrict requests coming from public folder) and evaluate it with beta testers.

@danilowoz danilowoz marked this pull request as ready for review July 8, 2024 14:09
DeMoorJasper
DeMoorJasper previously approved these changes Jul 8, 2024
Copy link
Member

@DeMoorJasper DeMoorJasper left a comment

Choose a reason for hiding this comment

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

Looks good, just left one comment for something we might need to keep an eye out for regarding breaking change

});

const parentPortPromise = new DeferredPromise<MessagePort>();
window.addEventListener(
Copy link
Member

Choose a reason for hiding this comment

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

This could potentially be a breaking change, but not sure if it would have a real impact?

@danilowoz danilowoz enabled auto-merge (squash) July 9, 2024 08:13
@danilowoz danilowoz disabled auto-merge July 9, 2024 08:59
alexnm
alexnm previously approved these changes Jul 9, 2024
@danilowoz danilowoz dismissed alexnm’s stale review July 9, 2024 09:41

The merge-base changed after approval.

@danilowoz danilowoz closed this Jul 9, 2024
@danilowoz danilowoz reopened this Jul 9, 2024
@danilowoz danilowoz merged commit 131c89f into master Jul 9, 2024
12 of 15 checks passed
@danilowoz danilowoz deleted the draft/boring-darwin branch July 9, 2024 10:05
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.

4 participants