-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
*/ | ||
if ( | ||
parsedUrl.origin !== self.location.origin || | ||
!parsedUrl.pathname.startsWith('/public') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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( |
There was a problem hiding this comment.
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?
…om/codesandbox/codesandbox-client into draft/boring-darwin
No description provided.