Coder Social home page Coder Social logo

codesandbox / sandpack-bundler Goto Github PK

View Code? Open in Web Editor NEW
52.0 11.0 10.0 1.79 MB

The new bundler/runtime powering client-side sandpack sandboxes

Home Page: https://sandpack-bundler.codesandbox.io

License: Apache License 2.0

HTML 0.26% TypeScript 99.11% JavaScript 0.63%
sandpack

sandpack-bundler's Introduction

Sandpack Bundler

The sandpack bundler, this aims to eventually replace the current sandpack with a more streamlined and faster version.

Getting started

  1. Run yarn to install dependencies.
  2. Run yarn dev to start the development server
  3. Set the bundlerURL of sandpack-react to http://localhost:1234/ to see it in action.

Test the production build (performance/integration tests)

  1. Run yarn to install dependencies.
  2. Run yarn build to build the application
  3. Run yarn start to start a local test server
  4. Set the bundlerURL of sandpack-react to http://localhost:4587/

Using the deployed version

The main branch of this repository is automatically deployed to https://sandpack-bundler.codesandbox.io so you can update bundlerURL of sandpack-react to that url and start using the new sandpack bundler.

sandpack-bundler's People

Contributors

compuives avatar danilowoz avatar demoorjasper avatar dependabot[bot] avatar lubieowoce avatar utwo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sandpack-bundler's Issues

Missing DOCTYPE causes browsers to use Quirks Mode

The bundled HTML doesn't have a doctype, meaning browsers choose quirks mode for the Sandpack previews. I noticed this on https://react.dev, which has many previews.

An easy way to reproduce is to check https://react.dev/learn

  • Firefox (v111.0) Open console and see the warning about Quirks Mode
  • Chrome (v111.0.5563.110) Open dev tools, select an iframe, in console run document.compatMode, which returns "BackCompat"
  • Safari (v16.3) Same as Chrome

It looks like the bundler starts with its own index.html and uses src/utils/html/replaceHTML to replace the body with the user's HTML body. Seems like the simplest fix is to add <!DOCTYPE html> to the start of the bundler's index.html. I ran react.dev and sandpack-bundler locally and that got rid of quirks mode.

The current approach is a little confusing, though. The user's own index.html (which sometimes comes from Sandpack's templates) gets passed to the bundler and then ignored, which made for a surprising debugging experience. In the long term, it would be nice if the index.html supplied by the user had priority over the bundler's index.html

Feature: dispatch bundler state from bundler to protocol

Currently, the v1 returns the bundler-state to Sandpack, which contains a lot of useful information. For example, the compiled files are mandatory information to render SandpackTranspiledCode.

V1: https://github.com/codesandbox/codesandbox-client/blob/master/packages/app/src/sandbox/compile.ts#L873-L876
Sandpack: https://github.com/codesandbox/sandpack/blob/main/sandpack-client/src/client.ts#L214-L217
Screenshot 2022-04-21 at 14 09 27
Screenshot 2022-04-27 at 17 03 05

If you point me out the right place, I can try to implement it

Failing to install npm dependencies when using self-hosted bundlerURL

Bug report

Packages affected

  • sandpack-client
  • sandpack-react

Description of the problem

I have this sandpack-bundler running: https://github.com/codesandbox/sandpack-bundler

In the example sandbox below, you will see I am setting the bundlerURL in the SandboxProvider.

The sandpack created doesn't actually work though due to failing to properly important the library. It works fine when I don't set bundlerURL and use the default bundler. Example of the error:

image

(Sometimes the error is about failing to import other stuff like Cannot find module 'process' from '/node_modules/vfile/lib/minproc.js')

It works fine when I try other libraries like "uuid: latest", but testing with "react-markdown: latest" has given me these errors. I've tried a couple other libraries and had issues with them too. It's like it's not doing npm install properly.

Again I should note that if I don't define bundlerURL and use the default, it works fine.

(Side note: sandpack-client and sandpack-react seem to use a different bundler version, 1.7.0 vs 1.8.8)

Link to sandbox: link

Your Environment

Software Name/Version
Sandpack-client version
Sandpack-react version 1.0.0 and also tried 1.8.8
Browser Chrome
Operating System MacOS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.