-
Notifications
You must be signed in to change notification settings - Fork 204
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
Add logic to represent booting state within preview panel and parse stdout from vite to get port #349
Conversation
…arse stdout from vite to get port
type ProcessMetadata = { | ||
process: ChildProcess; | ||
port: number | null; | ||
}; | ||
|
||
const processMetadata = new Map<string, ProcessMetadata>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that now, processes
is called processMetadata
and includes a process plus associated metadata (currently just the port it is running on).
switch (status) { | ||
case "booting": | ||
case "connecting": | ||
return ( | ||
<div className={cn("flex justify-center items-center w-full h-full", props.className)}> | ||
<span className="text-tertiary-foreground">Booting...</span> | ||
</div> | ||
); | ||
case "running": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -18,9 +18,16 @@ import { loadApp } from '../../apps/app.mjs'; | |||
import { fileUpdated, pathToApp } from '../../apps/disk.mjs'; | |||
import { vite } from '../../exec.mjs'; | |||
|
|||
const VITE_PORT_REGEX = /Local:.*http:\/\/localhost:([0-9]{1,4})/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the regex for extracting the port vite picks from stdout.
const potentialPortMatch = VITE_PORT_REGEX.exec(encodedData); | ||
if (potentialPortMatch) { | ||
const portString = potentialPortMatch[1]!; | ||
const port = parseInt(portString, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number(portString)
:)
const encodedData = data.toString('utf8'); | ||
console.log(encodedData); | ||
|
||
const potentialPortMatch = VITE_PORT_REGEX.exec(encodedData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be noted that chunks of data are not guaranteed to arrive deterministically in a way that we expect. This is why eg stream parsing is typically stateful. While I expect this to behave as we want it to, it's not guaranteed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, can we get this in?
type AppContextType = MessageContextType<'appId'>; | ||
|
||
const processes = new Map<string, ChildProcess>(); | ||
type ProcessMetadata = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also have the status "running"?
And potentially exit code
args: [], | ||
cwd: pathToApp(app.externalId), | ||
stdout: (data) => { | ||
console.log(data.toString('utf8')); | ||
const encodedData = data.toString('utf8'); | ||
console.log(encodedData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the 2 lines? Is there a behavior change?
…tdout from vite to get port (srcbookdev#349) * feat: add logic to represent booting state within preview panel and parse stdout from vite to get port * fix: run npm run format
#333) * [FIX]:285 - Type proccess.env based off the available secrets in a notebook * [ADD] - changeset * [FIX] - linting and formatting * Style apps page sidebar and header (#340) * Update sans font (#341) * File tree functionality and styles (#344) * Add support for deleting and renaming files (#345) * Add support for deleting and renaming files * Fix lint * Exclude a few directories * Implement top level create file and folder (#346) * Homepage UI Rework! (#348) * inital homepage rework, sections, card style, srcbook to notebook * fix lil linter error * move user facing Srcbook (in ref to notebook) to Notebook * style up to match figma * some cleanup around purples on create app (#351) * fix CI bug with pnpm CI mismatch in release (#354) * Add logic to represent booting state within preview panel and parse stdout from vite to get port (#349) * feat: add logic to represent booting state within preview panel and parse stdout from vite to get port * fix: run npm run format * Add folder delete and rename behavior (#355) * Add folder delete and rename behavior * Remove unused files state * Fix lint warnings * [FIX] - env type errors * put the env.d.ts file under root directory instead of src * remove cell:format --------- Co-authored-by: Ben Reinhart <[email protected]> Co-authored-by: versecafe <[email protected]> Co-authored-by: Ryan Gaus <[email protected]>
Currently, the preview panel in the app builder is a bit unreliable - when it opens, the iframe sometimes is pointing to the wrong vite server or nothing at all.
This pull request attempts to make this behavior more consistient, by doing three things:
preview:start
message is sent to the server, the server now sends back apreview:status
message including astatus
of"booting"
. - the client then shows a loading indicator. Once a port is detected in the stdout, a secondary message is sent to the client including this port, and the loading indicator goes away, and an iframe is rendered going to this port.1.
is sent back to the client again, resulting in the preview panel opening back up to the correct url.