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

[widgets] Support serving a basic widget manifest in vite serve mode #1022

Merged
merged 9 commits into from
Nov 27, 2024

Conversation

styu
Copy link
Contributor

@styu styu commented Nov 27, 2024

This augments the widget vite plugin to serve a basic form of the manifest so that we can trigger a localhost-driven developer mode against a Foundry environment. The workflow would look like the following:

  1. Set your FOUNDRY_TOKEN in your terminal
  2. Make sure your foundry.config.json is set
  3. Run dev
  4. Click on the indicated URL in the terminal output

image

  1. Wait for the page to redirect you to Foundry
  2. Land in developer mode within our preview harness UI

Some considerations for this (incomplete) version:

  • I haven't fully figured out how HMR should work. I think there's something funky in either the order in which vite traverses the module graph (and thus our scripts in the manifest are out of order) or with a script tag that has inline JS that appears on the page for react refresh window variables :|
  • Vite does not parse modules in dev mode for performance reasons. This means that although we can (more or less) find the entrypoint assets to add to the manifest, in dev mode the parameter/event config is not getting served. We could perhaps find the imported .config file and parse it on the fly instead, if that's not too expensive?
  • This currently isn't handling CSS specially - it's mostly assuming that a JS file has imported the CSS. If there is a css file referenced in the HTML instead, I'm not sure what will happen
  • This is calling an internal/beta endpoint, which should be published to our public API at some point instead
  • Vite in serve mode is extremely conservative, and refuses to load any modules until the very last moment. As a result, I ended up making a tiny little app that is served by vite at ./palantir/setup, which will receive the list of HTML entrypoint files and then load them in invisible iframes. The loading of these HTML files triggers the vite plugin code which goes and logs all the JS entrypoint files, which we then use to compose a manifest file. The tiny app then sits there and polls for the manifest until it sees an entrypoint file for every manifest, and then it tells the plugin to send the manifest to Foundry. If successful, it will redirect the dev to Foundry to see their widget in the preview harness
  • I'm not handling the multiple entrypoint case, since it requires parsing the config file to figure out which RID the dev actually wants/intends. I think platinum version, the tiny app hosted by the vite plugin probably shows a selector to pick which entrypoint they want to launch dev mode for, and then the corresponding RID is found and used to start dev mode

@rosscourt rosscourt merged commit 91a54a3 into main Nov 27, 2024
8 checks passed
@rosscourt rosscourt deleted the syu/widget-vite-serve-mode branch November 27, 2024 19:07
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.

2 participants