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

Merged
merged 4 commits into from
Jan 17, 2025

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.

thecodacus
thecodacus previously approved these changes Jan 15, 2025
@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
@Stijnus
Copy link
Author

Stijnus commented Jan 16, 2025

Hi Guys,

I have made some tweakes (did not ad the code in this PR)i but here is a screenshot :

Predefined Window Sizes:

Size Selection UI:

Main button opens preview in current size
Dropdown button shows size options
Each size option shows dimensions
Clean dropdown menu styling

Usage:

Click the main button to open in current size
Click the dropdown arrow to see size options
Select a size to open in that dimension
Window opens with clean UI (no browser chrome)
The new UI looks like:

Try it out:
Click the dropdown arrow
Select a device size
Preview opens in a new window with those exact dimensions
Each size gives you a different viewport for testing

image image

Br,

Stijn

[Open Preview] [▼]  // Two buttons side by side
    |
    +-- [Mobile (375x667)]    // Dropdown menu
    |-- [Tablet (768x1024)]
    |-- [Laptop (1366x768)]
    +-- [Desktop (1920x1080)]
@leex279
Copy link
Collaborator

leex279 commented Jan 17, 2025

@Stijnus looks nice. Add them in a new PR, so we can test it out :)

@Stijnus
Copy link
Author

Stijnus commented Jan 17, 2025

@Stijnus looks nice. Add them in a new PR, so we can test it out :)

Give 30 min will update soon finishing other Dev project first :)

@Stijnus
Copy link
Author

Stijnus commented Jan 17, 2025

Hi, I have update the PR please test if you have the time :)

Br,

Stijnus

@leex279 leex279 requested review from thecodacus and leex279 January 17, 2025 19:57
Copy link
Collaborator

@leex279 leex279 left a comment

Choose a reason for hiding this comment

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

everything looks good

@thecodacus thecodacus merged commit 87ff810 into stackblitz-labs:main Jan 17, 2025
3 checks passed
@mrsimpson
Copy link
Collaborator

Merged 🎉
What a great contribution. Thx, @Stijnus

Interested to see whether this work on electron too, @thecodacus

@thecodacus
Copy link
Collaborator

Interested to see whether this work on electron too, @thecodacus

I am also not sure. 😅

@Stijnus
Copy link
Author

Stijnus commented Jan 17, 2025

Merged 🎉 What a great contribution. Thx, @Stijnus

Interested to see whether this work on electron too, @thecodacus

Thank you...

a mention in the readme would be nice 😊

@thecodacus
Copy link
Collaborator

this works with that also.

image

a mention in the readme would be nice 😊

ohh man why didn't you update it.., I will add it on my next PR

@Stijnus
Copy link
Author

Stijnus commented Jan 17, 2025

this works with that also.

image

a mention in the readme would be nice 😊

ohh man why didn't you update it.., I will add it on my next PR

my bad... thank you

@leex279
Copy link
Collaborator

leex279 commented Jan 18, 2025

@Stijnus just saw the contrast is very bad for dark mode:
image

maybe you can fix that in another PR :)

@Stijnus
Copy link
Author

Stijnus commented Jan 18, 2025 via email

@mrsimpson
Copy link
Collaborator

Then don't forget to add yourself to the readme ;-)

@Stijnus
Copy link
Author

Stijnus commented Jan 18, 2025 via email

@leex279
Copy link
Collaborator

leex279 commented Jan 18, 2025

Just in time before I do my next video :D thanks.

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