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: added the "Open Preview in a New Tab" #1101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Stijnus
Copy link

@Stijnus Stijnus commented Jan 15, 2025

image image

@thecodacus
Copy link
Collaborator

is this ready?

@Stijnus
Copy link
Author

Stijnus commented Jan 15, 2025

I did my testing on my end but Yes it should be ready but please to be sure test before you merge it.

thx,

Br,
Stijn

@leex279
Copy link
Collaborator

leex279 commented Jan 15, 2025

Nice on. works fine for me so far. Just one thing, but not a must => if the external preview is open, can we prevent from switching to the preview tab within the main ui? So stay on code editor.

@Stijnus
Copy link
Author

Stijnus commented Jan 15, 2025

Nice on. works fine for me so far. Just one thing, but not a must => if the external preview is open, can we prevent from switching to the preview tab within the main ui? So stay on code editor.

like a detach window function or how i need to interper it ? can you be more precise?

@leex279
Copy link
Collaborator

leex279 commented Jan 15, 2025

This I mean. When bolt is done with coding (finished the prompt), its automatically switching to preview, what I dont like when the external preview in a new tab is already open. Then I want to stay on code-editor.

switch

@thecodacus
Copy link
Collaborator

just need to update the logic here if the preview is opened in another tab don't switch

image

@thecodacus
Copy link
Collaborator

thecodacus commented Jan 15, 2025

this is bolt.new when the chat is hidden, might be good for another PR
Screenshot 2025-01-15 at 10 50 22 PM

@thecodacus
Copy link
Collaborator

I was thinking about it, i don't think there is any way to communicate between these two tabs. so don't know how this is possible. I suggest we merge this PR and open a separate PR to explore this concept.

@Stijnus
Copy link
Author

Stijnus commented Jan 15, 2025

I was thinking about it, i don't think there is any way to communicate between these two tabs. so don't know how this is possible. I suggest we merge this PR and open a separate PR to explore this concept.

ì was playing arround this today after the PR :

The fundamental issue is that the web app running inside the WebContainer iframe has its own isolated context, regardless of whether it uses localStorage or not.

Here's what's happening:

  1. Each preview tab has its own isolated WebContainer environment
  2. Changes made in one WebContainer environment don't automatically propagate to another
  3. Even without localStorage, each iframe has its own memory/state
  4. The WebContainer isolation is by design for security and stability

The current approach of trying to sync through the parent window's localStorage or broadcast channels won't work because:

  1. The WebContainer iframe is isolated from the parent window
  2. Each WebContainer instance is independent
  3. We can't directly access or modify the state inside the WebContainer from outside

Possible solutions could be:

  1. WebContainer API Communication:

    • Set up a message passing system between the WebContainer and parent
    • Have the WebContainer app emit state changes
    • Parent receives and broadcasts these to other tabs
    • Other tabs tell their WebContainer to update
  2. Shared Backend Storage:

    • Instead of localStorage, use a shared backend storage
    • All WebContainer instances read/write to same storage
    • Changes would be visible to all instances

@leex279
Copy link
Collaborator

leex279 commented Jan 15, 2025

thanks for investigating and summarizing this. I just saw it works the same in bolt.new, so I assume this is correct what you found out.

@patak-dev but maybe you want to change/enhance this as well for bolt.new, then we can use it as well :P
=> #1101 (comment)

@patak-dev
Copy link
Collaborator

Makes sense @leex279, thanks for the heads up!

@mrsimpson
Copy link
Collaborator

mrsimpson commented Jan 16, 2025

@Stijnus sli.dev, a browser based presentation tool also uses BroadcastChannels for communicating changes across tabs and even windows and it's a very robust and responsive experience.

Would it not be possible to have a thin shell around the webcontainer which listens to the broadcast and then propagates to the webcontainer? Or is this what you meant with "Set up a message passing system between the WebContainer and parent"

@thecodacus thecodacus added the ui-enhancement Enhancement made to the UI label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ui-enhancement Enhancement made to the UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants