-
Notifications
You must be signed in to change notification settings - Fork 279
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
fix: Local image resolution not working in IDE #1037
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1037 +/- ##
=======================================
Coverage 63.48% 63.48%
=======================================
Files 59 59
Lines 7115 7115
Branches 1583 1583
=======================================
Hits 4517 4517
Misses 2502 2502
Partials 96 96 Continue to review full report at Codecov.
|
Deploying with Cloudflare Pages
|
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.
I like the idea of serving branch-specific registry. This is useful for debugging and previewing. However, I think a more general solution I mentioned below will take the same LOCs, and make a simpler build script. We really shouldn't run monorepo-level build script in docs-site
and need to find a more sustainable option (e.g. CI script, node script, or Cloudflare-supported monorepo deployment whenever it's available). That aside, using local storage will free us from copying the SVG files and open up the path for local file uploads in the future.
@@ -142,21 +142,21 @@ forall Point p { | |||
center: p.circle1.center | |||
width: p.circle1.r * 2.0 | |||
height: p.circle1.r * 2.0 | |||
href: "shading.svg" | |||
href: "persistent-homology-shading.svg" |
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.
I don't follow the renaming here: is this for disambiguating shading.svg
?
In general, I still don't think it's a great idea to put all images for all domains in one flat folder. Even if we are serving the examples, we can still keep the folder structure and resolve the image paths by domain-prefix + relative-image-path
. No need to move all images to a different folder.
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.
Thanks for reviewing this. As you noted below, once an example is modified, we lose the example root
information and no longer know which folder contains the image resource. If there are different, for example, shading.svg
s in different folders, it becomes ambiguous which one to choose.
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.
Like I said below, you can use the workspace id to disambiguate across sessions if using local storage.
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.
Actually there's no need to cache image from previous sessions. Within a Style program, images should be unique, so we can cache them when we are in the example phase, and just retrieve the images in local mode.
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.
Thanks and a few clarifying questions since I am new to the new IDE. How are we currently defining session
and workspace id
? How is the workspace id
accessed and when do we generate a new id? In the described workflow, are we requiring a user to load an example with the stock images he or she wants prior to using them in their own diagram? How do we want to invalidate the entries we create in local storage, particularly if they are workspace id specific -- whenever the workspace id
changes? Thanks for helping with the additional context!
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.
Thanks and a few clarifying questions since I am new to the new IDE. How are we currently defining session and workspace id? How is the workspace id accessed and when do we generate a new id?
WorkspaceMetadata
has the ID of the current workspace, which is roughly identified by a trio of Penrose programs. So whenever you load a new trio, uuid()
is called to generate a new ID. You can simply search for all invocations for uuid()
to see the call sites. The state management is done by recoil, so maybe look at https://recoiljs.org to see how it works.
In the described workflow, are we requiring a user to load an example with the stock images he or she wants prior to using them in their own diagram?
Not sure if I understand the question. Image loading is done automatically if loading from gist, examples, or roger. Are you talking about the user uploading their own image? In that case, yeah I hope we can build that fairly easily (ie a simple file dialog can be a good starter).
How do we want to invalidate the entries we create in local storage, particularly if they are workspace id specific -- whenever the workspace id changes?
Yeah, except when the workspaces are explicitly saved. You can get the list of these ids from localFilesState
.
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.
Thanks, in the latest commit, local storage images are workspace id
specific. The editor was creating new uuid
s when a workspace was saved, which caused saved workspaces to lose their images. I removed the line of code creating the new uuid on workspace save.
It seems it would be better if the images were stored within the Recoil workspace state rather than outside of it. For instance, when a saved workspace is deleted by the user, Recoil would also delete the images from local storage. Right now these images accumulate each time a workspace with images is created and never go away.
My suggestion is to move ahead with this PR since it fixes a bug in production and create an issue to move image resource management into Recoil state.
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.
Thanks for making the changes! Now that we are use local storage, I think the svg
public folder is no longer necessary. My comments are mostly about removing that. Once that's done, we can undo the file renamings too.
relativePath, | ||
new URL( | ||
relativePath, | ||
window.location.origin + window.location.pathname + "svg/" |
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.
Instead of hard-coding the svg/
path, local
workspace should only get the image from local storage because the image must came from gist, example, roger, or file upload (this is not implemented but doesn't change the logic) which already cache to local storage when loaded
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.
Removed. This breaks the ability for example images to work for trios that are pasted in, but that doesn't sound like a user case we are supporting right now, which would make this unnecessary.
packages/editor/.gitignore
Outdated
@@ -8,6 +8,8 @@ pnpm-debug.log* | |||
lerna-debug.log* | |||
|
|||
node_modules | |||
public/svg |
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.
Okay to deploy the example source files, but svgs shouldn't be in the same folder anymore, so this shouldn't be needed.
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.
Removed.
packages/editor/package.json
Outdated
@@ -6,9 +6,9 @@ | |||
"start": "vite", | |||
"dev": "vite", | |||
"watch": "vite", | |||
"clean": "rimraf dist", | |||
"clean": "rimraf dist;rimraf public/svg;rimraf public/examples", |
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.
No need to have svg
folder.
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.
Also do rimraf dist public/examples
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.
Removed
packages/editor/package.json
Outdated
"typecheck": "tsc --noEmit", | ||
"build": "NODE_OPTIONS='--max-old-space-size=8192' vite build", | ||
"build": "shx mkdir -p ./public/svg/;shx cp ../examples/src/*/*.svg ./public/svg;shx mkdir -p ./public/examples/;shx cp -r ../examples/src/* ./public/examples/;NODE_OPTIONS='--max-old-space-size=8192' vite build", |
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 remove the svg
related steps
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.
Removed
Description
Resolves #1035.
This PR implements local serving of images and examples in the IDE. This has two benefits:
Implementation strategy and design decisions
During build, examples and images are deployed to vite's
public
directory (documentation) and are served locally from there.Open questions