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

Browser preview debug UI #2803

Merged
merged 19 commits into from
Jul 26, 2024
Merged

Conversation

macintoshhelper
Copy link
Contributor

Why does this PR exist?

#2710 #2709

What does this pull request do?

Testing this change

Additional Notes (if any)

Copy link

changeset-bot bot commented May 29, 2024

⚠️ No Changeset found

Latest commit: 92848d5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

github-actions bot commented Jul 5, 2024

Commit SHA:823bc03ae332be015f20b6917e8ead28b647f389

Test coverage results 🧪

Code coverage diff between base branch:feat/browser-plugin-sync and head branch: feat/browser-preview-debug-ui 
Status File % Stmts % Branch % Funcs % Lines
🔴 total 66.85 (-0.65) 57.86 (-0.59) 63.78 (-0.61) 67.21 (-0.67)
🟢 packages/tokens-studio-for-figma/src/plugin/controller.ts 98.03 (0.03) 100 (0) 75 (0) 100 (0)
✨ 🆕 packages/tokens-studio-for-figma/src/plugin/asyncMessageHandlers/preview.ts 33.33 100 0 33.33

Copy link
Contributor

github-actions bot commented Jul 5, 2024

Commit SHA:823bc03ae332be015f20b6917e8ead28b647f389
Current PR reduces the test coverage percentage by 1 for some tests

Copy link
Contributor

@cuserox cuserox left a comment

Choose a reason for hiding this comment

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

Great job 🎉

Again, a few questions as I explored the setup.

We could pair on the next steps of creating actions? If that's a thing :)


1. Open two Terminal windows/tabs

> Terminal 1 (Plugin)
Copy link
Contributor

Choose a reason for hiding this comment

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

Explaining what this does, like yarn would be useful, for users like me that couldn't get it first time!

> Terminal 2 (Browser)

```sh
npm run preview:browser
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, explaining that this needs to be loaded completely, before running the plugin, would help for understanding 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Finally, an overview of what one expects to see when this is running 🙏

No need to be super thorough but more like:

Open the browser, when all assets are loaded, then open the plugin, etc

Copy link
Contributor

Choose a reason for hiding this comment

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

Are these new commands fully working or WIP?

If fully working, then it's worth adding it to the docs 👏

@@ -25,7 +25,8 @@ wss.on("connection", (ws) => {
});

// connection is up, let's add a simple simple event
ws.on("message", (message) => {
ws.on("message", (data, isBinary) => {
const message = isBinary ? data : data.toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

What does isBinary mean & do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depending on the version of ws installed, the data might be sent as a buffer, or as a string. This step makes sure that it is only a string. Buffer may be better for performance (such as large payloads or streams).

Should probably explicitly install ws as a dependency.

Text messages and close reasons are no longer decoded to strings. They are passed as Buffers to the listeners of their respective events. The listeners of the 'message' event now take a boolean argument specifying whether or not the message is binary (e173423).

https://stackoverflow.com/a/69485504

}, [value, handleClose]);

return (
<form onSubmit={checkAndSubmitMessage} style={{ display: 'flex', flexGrow: 1, height: '100%' }}>
Copy link
Contributor

Choose a reason for hiding this comment

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

As I know it's still WIP, could we put an icon or small message that this is not ready yet? 🔨

window.location.hash = `#${urlParams.toString()}`;
}, []);

return { data, updateHash };
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessary now, but perhaps it could be worth replacing this URL / route / state handling with a router solution? Like https://tanstack.com/router/latest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

react-router could be good, together with createMemoryRouter: https://github.com/rlingineni/figma-plugin-react-template/blob/main/src/app/App.tsx#L8-L27

Didn't want to change routing logic for the whole plugin in this PR.

@@ -335,6 +336,9 @@ AsyncMessageTypes.REMOVE_RELAUNCH_DATA,
}
>;

export type PreviewRequestStartupAsyncMessage = AsyncMessage<AsyncMessageTypes.PREVIEW_REQUEST_STARTUP>;
export type PreviewRequestStartupAsyncMessageResult = AsyncMessage<AsyncMessageTypes.PREVIEW_REQUEST_STARTUP>;
Copy link
Contributor

Choose a reason for hiding this comment

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

No extra data returned in the result?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't need to return any data, so removed the reply msg. Could pass { success: true } or something maybe

@macintoshhelper macintoshhelper marked this pull request as ready for review July 17, 2024 14:37
Copy link
Contributor

⤵️ 📦 ✨ The artifact was successfully created! Want to test it? Download it here 👀 🎁

@six7 six7 merged commit dce52fb into feat/browser-plugin-sync Jul 26, 2024
5 of 6 checks passed
@six7 six7 deleted the feat/browser-preview-debug-ui branch July 26, 2024 17:52
six7 added a commit that referenced this pull request Jul 26, 2024
* [WIP] webpack config setup for fast refresh + websocket server

* add prod/dev hmr webpack config option

* render immediately and handle AsyncMessage in startup app hook

* forward ui AsyncMessages to browser via WebSockets

* null check sentry transaction to fix browser error

* refactor AsyncMessageChannel code for browser implementation

* webpack use swc-loader for browser version + speed/bundle size plugin options

* prettify browser dev preview UI

* enable loading screen if startup params missing (for web serve + disconnected browser dev preview)

* attempt to fix webpack build for tests

* add SpeedMeasurePlugin package

* create AsyncMessageChannel dev docs

* replace web-preview.md ASCII data flow diagram with mermaid

* use radii/spacing tokens instead of px for web preview.tsx styles

Co-authored-by: Jan Six <[email protected]>

* remove commented out startup handler (handled in startup.tsx useEffect now)

Co-authored-by: Jan Six <[email protected]>

* remove commented out code

Co-authored-by: Jan Six <[email protected]>

* replace px values with tokens

Co-authored-by: Jan Six <[email protected]>

* conditional export for AsyncMessageChannel preview env

* add browser preview WEBSOCKETS_PORT env

* fix typescript issue with PreviewAsyncMessageChannel.isWsConnected

* add test coverage for AsyncMessageChannelPreview

* Browser preview debug UI (#2803)

* fix AsyncMessageChannelPreview undefined error + export WS URI

* browser preview CSS file for UI fixes

* create previewUtils for browser color scheme + setFigmaBrowserTheme

* browser preview URL params + fullscreen/theme/action modes

* two bug fixes for browser/plugin websocket preview bridge

* add preview dist folder for web preview builds

* [WIP] browser preview dev knowledge docs

* feat(dev): request startup on browser preview page open

* refactor(dev): use env vars for browser preview ws src

* fix(debug): remove console.log from asyncmessagechannelpreview

* fix(css): figmaloading full height css for browser preview

* refactor(dev): use enums for websockets src in browser preview tsx

* fix(dev): remove comments

* refactor: reuse htmlClassList variable

* remove unused package

---------

Co-authored-by: macintoshhelper <[email protected]>

---------

Co-authored-by: macintoshhelper <[email protected]>
Co-authored-by: Jan Six <[email protected]>
cuserox pushed a commit that referenced this pull request Aug 22, 2024
* [WIP] webpack config setup for fast refresh + websocket server

* add prod/dev hmr webpack config option

* render immediately and handle AsyncMessage in startup app hook

* forward ui AsyncMessages to browser via WebSockets

* null check sentry transaction to fix browser error

* refactor AsyncMessageChannel code for browser implementation

* webpack use swc-loader for browser version + speed/bundle size plugin options

* prettify browser dev preview UI

* enable loading screen if startup params missing (for web serve + disconnected browser dev preview)

* attempt to fix webpack build for tests

* add SpeedMeasurePlugin package

* create AsyncMessageChannel dev docs

* replace web-preview.md ASCII data flow diagram with mermaid

* use radii/spacing tokens instead of px for web preview.tsx styles

Co-authored-by: Jan Six <[email protected]>

* remove commented out startup handler (handled in startup.tsx useEffect now)

Co-authored-by: Jan Six <[email protected]>

* remove commented out code

Co-authored-by: Jan Six <[email protected]>

* replace px values with tokens

Co-authored-by: Jan Six <[email protected]>

* conditional export for AsyncMessageChannel preview env

* add browser preview WEBSOCKETS_PORT env

* fix typescript issue with PreviewAsyncMessageChannel.isWsConnected

* add test coverage for AsyncMessageChannelPreview

* Browser preview debug UI (#2803)

* fix AsyncMessageChannelPreview undefined error + export WS URI

* browser preview CSS file for UI fixes

* create previewUtils for browser color scheme + setFigmaBrowserTheme

* browser preview URL params + fullscreen/theme/action modes

* two bug fixes for browser/plugin websocket preview bridge

* add preview dist folder for web preview builds

* [WIP] browser preview dev knowledge docs

* feat(dev): request startup on browser preview page open

* refactor(dev): use env vars for browser preview ws src

* fix(debug): remove console.log from asyncmessagechannelpreview

* fix(css): figmaloading full height css for browser preview

* refactor(dev): use enums for websockets src in browser preview tsx

* fix(dev): remove comments

* refactor: reuse htmlClassList variable

* remove unused package

---------

Co-authored-by: macintoshhelper <[email protected]>

---------

Co-authored-by: macintoshhelper <[email protected]>
Co-authored-by: Jan Six <[email protected]>
macintoshhelper added a commit that referenced this pull request Oct 24, 2024
* Browser plugin preview (#2748)

* [WIP] webpack config setup for fast refresh + websocket server

* add prod/dev hmr webpack config option

* render immediately and handle AsyncMessage in startup app hook

* forward ui AsyncMessages to browser via WebSockets

* null check sentry transaction to fix browser error

* refactor AsyncMessageChannel code for browser implementation

* webpack use swc-loader for browser version + speed/bundle size plugin options

* prettify browser dev preview UI

* enable loading screen if startup params missing (for web serve + disconnected browser dev preview)

* attempt to fix webpack build for tests

* add SpeedMeasurePlugin package

* create AsyncMessageChannel dev docs

* replace web-preview.md ASCII data flow diagram with mermaid

* use radii/spacing tokens instead of px for web preview.tsx styles

Co-authored-by: Jan Six <[email protected]>

* remove commented out startup handler (handled in startup.tsx useEffect now)

Co-authored-by: Jan Six <[email protected]>

* remove commented out code

Co-authored-by: Jan Six <[email protected]>

* replace px values with tokens

Co-authored-by: Jan Six <[email protected]>

* conditional export for AsyncMessageChannel preview env

* add browser preview WEBSOCKETS_PORT env

* fix typescript issue with PreviewAsyncMessageChannel.isWsConnected

* add test coverage for AsyncMessageChannelPreview

* Browser preview debug UI (#2803)

* fix AsyncMessageChannelPreview undefined error + export WS URI

* browser preview CSS file for UI fixes

* create previewUtils for browser color scheme + setFigmaBrowserTheme

* browser preview URL params + fullscreen/theme/action modes

* two bug fixes for browser/plugin websocket preview bridge

* add preview dist folder for web preview builds

* [WIP] browser preview dev knowledge docs

* feat(dev): request startup on browser preview page open

* refactor(dev): use env vars for browser preview ws src

* fix(debug): remove console.log from asyncmessagechannelpreview

* fix(css): figmaloading full height css for browser preview

* refactor(dev): use enums for websockets src in browser preview tsx

* fix(dev): remove comments

* refactor: reuse htmlClassList variable

* remove unused package

---------

Co-authored-by: macintoshhelper <[email protected]>

---------

Co-authored-by: macintoshhelper <[email protected]>
Co-authored-by: Jan Six <[email protected]>

* Browser plugin preview (#2748)

* [WIP] webpack config setup for fast refresh + websocket server

* add prod/dev hmr webpack config option

* render immediately and handle AsyncMessage in startup app hook

* forward ui AsyncMessages to browser via WebSockets

* null check sentry transaction to fix browser error

* refactor AsyncMessageChannel code for browser implementation

* webpack use swc-loader for browser version + speed/bundle size plugin options

* prettify browser dev preview UI

* enable loading screen if startup params missing (for web serve + disconnected browser dev preview)

* attempt to fix webpack build for tests

* add SpeedMeasurePlugin package

* create AsyncMessageChannel dev docs

* replace web-preview.md ASCII data flow diagram with mermaid

* use radii/spacing tokens instead of px for web preview.tsx styles

Co-authored-by: Jan Six <[email protected]>

* remove commented out startup handler (handled in startup.tsx useEffect now)

Co-authored-by: Jan Six <[email protected]>

* remove commented out code

Co-authored-by: Jan Six <[email protected]>

* replace px values with tokens

Co-authored-by: Jan Six <[email protected]>

* conditional export for AsyncMessageChannel preview env

* add browser preview WEBSOCKETS_PORT env

* fix typescript issue with PreviewAsyncMessageChannel.isWsConnected

* add test coverage for AsyncMessageChannelPreview

* Browser preview debug UI (#2803)

* fix AsyncMessageChannelPreview undefined error + export WS URI

* browser preview CSS file for UI fixes

* create previewUtils for browser color scheme + setFigmaBrowserTheme

* browser preview URL params + fullscreen/theme/action modes

* two bug fixes for browser/plugin websocket preview bridge

* add preview dist folder for web preview builds

* [WIP] browser preview dev knowledge docs

* feat(dev): request startup on browser preview page open

* refactor(dev): use env vars for browser preview ws src

* fix(debug): remove console.log from asyncmessagechannelpreview

* fix(css): figmaloading full height css for browser preview

* refactor(dev): use enums for websockets src in browser preview tsx

* fix(dev): remove comments

* refactor: reuse htmlClassList variable

* remove unused package

---------

Co-authored-by: macintoshhelper <[email protected]>

---------

Co-authored-by: macintoshhelper <[email protected]>
Co-authored-by: Jan Six <[email protected]>

* update web preview script docs

* fix: updateStyles error from merge conflict

* lint: remove comments and cleanup

* fix: language switch on startup for new preview startup

* lint: remove more comments from preview files

* lint: fix indentation error because of prettier conflict

---------

Co-authored-by: macintoshhelper <[email protected]>
Co-authored-by: Jan Six <[email protected]>
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.

3 participants