Skip to content

Conversation

knervous
Copy link
Contributor

First I'd like to apologize for the size of this PR. It started as a proof of concept and slowly turned into a large undertaking that necessitated a full pass at compatibility and potential regressions. There are also features baked into this whole system that aren't necessary to the core elements. I appreciate the risk of a merge this big so welcome any opportunity to make it accessible. I also have been using this version since its inception and am coming away with a very new and fresh perspective on using the PG to iterate and build out code + showcase work. I'll try to keep the rest brief:

Goals:
Adding new functionality to the Playground Code Editor to support larger / more complex examples as well as have it serve as a unique sandbox for BJS developers to prove out their code in a more fully-fledged environment.

Non-goals:
"Refactoring" for the sake of refactoring, or injecting unnecessary changes based on my style, preference, modern standards, yada yada... I tried to conform to the existing architecture where possible and otherwise keep SOLID principles in play. The linting standards really helped keep things cohesive!

Full feature set:

  • Multiple file support in the Monaco code editor
  • Add/remove/rename files, drag to reorder, change entrypoint for code execution
  • Support for local module imports/exports (e.g. import MyClass from './module.ts'
  • Support for NPM modules (mileage may vary here - service has a baked in Automatic Type Acquisition to provide intellisense and code diagnostics)
  • Support for local NPM module linking (Importing as import myDevClass from 'dev-package@local' provides a code lens item to link the output directory though the FileSystem)
  • Local session storage/retrieval. This is a solution for "lost work" through runtime crashes, infinite loops, accidental page navigation. Sessions can be restored through a #local revision suffix or a dialog of managed sessions

Current deployment:
I have been deploying this through a lightweight vercel app which builds the core build dependencies and builds the SPA and serves directly. This is available at https://playgroundv2.vercel.app . It would likely be very helpful to get a request for feedback for use while this is deployed as it will reflect the current state of this branch.

Core arch changes:
Code is not stored as a single block of text now but rather a manifest JSON blob defined as

export type V2Manifest = {
    v: 2;
    language: "JS" | "TS";
    entry: string;
    imports: Record<string, string>;
    files: Record<string, string>;
    cdnBase?: string;
};

The used fields here are language, entry and files while the others are placeholders for additional enhancements/validation checks down the line, i.e. versioning for backwards compatibility.

Compatibility:
All previous Playgrounds will be able to be loaded as-is and be compatible with this editor. Any saved PG moving forward will then save the JSON manifest blob and therefore not be backwards compatible. The idea being "this is what the spec is" moving forward and not having code paths to continue legacy save support.

User-facing changes:
From the user's perspective, new and existing Playgrounds will load as usual and the only noticeable difference will be the tab bar on the top of the editor. There's a lot going on beneath the hood but it shouldn't be a jarring UI change.

Tests performed:
I have tested the following:

  • Code snippet insertion
  • Loading all the examples from within the Playground page
  • Download (this needed a whole rewrite due to virtual file structure)
  • All the normal paths of save/load

Next steps
Documentation! And examples of the best ways to leverage this system.

Appreciate the time spent reading through this and taking the features into consideration. FWIW I have been a full stack dev for about a decade primarily working with React and have worked with Monaco in multiple projects, happy to commit to maintaining and improving these changes here when necessary.

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 24, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 24, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 24, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 24, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 25, 2025

Reviewer - this PR has made changes to one or more package.json files.

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 25, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 25, 2025

Reviewer - this PR has made changes to one or more package.json files.

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 25, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 25, 2025

You have made possible changes to the playground.
You can test the snapshot here:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/PLAYGROUND/refs/pull/17175/merge/

The snapshot playground with the CDN snapshot (only when available):

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/PLAYGROUND/refs/pull/17175/merge/?snapshot=refs/pull/17175/merge

Note that neither Babylon scenes nor textures are uploaded to the snapshot directory, so some playgrounds won't work correctly.

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 25, 2025

You have changed file(s) that made possible changes to the sandbox.
You can test the sandbox snapshot here:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/SANDBOX/refs/pull/17175/merge/

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 25, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 25, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 25, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 25, 2025

VicenteCartas added a commit to BabylonJS/Documentation that referenced this pull request Sep 26, 2025
This PR updates the Playground search page to handle the new manifest
that the Playground V2 uses (from this PR:
BabylonJS/Babylon.js#17175).

The schema of the manifest of the PG V2 is defined as:
```
export type V2Manifest = {
    v: 2;
    language: "JS" | "TS";
    entry: string;
    imports: Record<string, string>;
    files: Record<string, string>;
    cdnBase?: string;
};
```

For search, we care about the _files_ property, which contains pairs
with the name of the file and the code of the file. Most of the parsing
changes are related to dealing with the fact that now there are multiple
files to search in a PG and to surface the name of the file where the
code is found (if we are searching by Code).

All search behavior is identical for V1 and V2, except for the following
changes:
- If the playground is a V2 playground, when searching for code with an
exact match the name of the file will be printed with the results:
<img width="1869" height="1069" alt="image"
src="https://github.com/user-attachments/assets/72d96489-08e8-41ae-a065-08c3dee4abbf"
/>
- Ellipsis in the code are removed for long lines, this is done to
simplify the code that handles finding the correct line and the current
page handles long lines correctly by wrapping the lines.
@Popov72
Copy link
Contributor

Popov72 commented Sep 28, 2025

I noticed that when you copy an import like import { X } from "./file.ts"; to another file, you get a TS error (PG: https://playgroundv2.vercel.app/#YX6IB8#965, I copied the line from index.ts):

image

If you remove the "./" and add it back, the error disappears.

@knervous
Copy link
Contributor Author

I noticed that when you copy an import like import { X } from "./file.ts"; to another file, you get a TS error (PG: https://playgroundv2.vercel.app/#YX6IB8#965, I copied the line from index.ts):

image If you remove the "./" and add it back, the error disappears.

Nice catch, the issue was some initial ambient module declaration that shadowed the real module. Tested some cases locally and pushed the change here

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 29, 2025

Reviewer - this PR has made changes to one or more package.json files.

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 29, 2025

You have changed file(s) that made possible changes to the sandbox.
You can test the sandbox snapshot here:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/SANDBOX/refs/pull/17175/merge/

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 29, 2025

You have made possible changes to the playground.
You can test the snapshot here:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/PLAYGROUND/refs/pull/17175/merge/

The snapshot playground with the CDN snapshot (only when available):

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/PLAYGROUND/refs/pull/17175/merge/?snapshot=refs/pull/17175/merge

Note that neither Babylon scenes nor textures are uploaded to the snapshot directory, so some playgrounds won't work correctly.

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 29, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 29, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 29, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Sep 29, 2025

@deltakosh
Copy link
Contributor

@VicenteCartas is it ok to merge now?

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.

9 participants