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

Fix the embedded Lite apps in the docs #10488

Merged
merged 7 commits into from
Feb 11, 2025
Merged

Conversation

whitphx
Copy link
Member

@whitphx whitphx commented Feb 3, 2025

Description

The embedded <gradio-lite> apps' style is broken as below, and 6bb14ca fixes it.
CleanShot 2025-02-03 at 16 43 42@2x

2178f48 is a related refactoring: I found that each component is loading lite.css in each Svelte file (and 6bb14ca did the same in the document markdown file), so lite.js should also be loaded by each component, instead of being loaded globally in +layout.svelte.

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Feb 3, 2025

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/211698e5d98fcc8ed556c565ae9ff76484e78163/gradio-5.14.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@211698e5d98fcc8ed556c565ae9ff76484e78163#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/211698e5d98fcc8ed556c565ae9ff76484e78163/gradio-client-1.10.0.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/211698e5d98fcc8ed556c565ae9ff76484e78163/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Feb 3, 2025

🦄 no changes detected

This Pull Request does not include changes to any packages.

__No changes detected. __

  • Maintainers can select this checkbox to manually select packages to update.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can create the changelog file directly.

@whitphx whitphx changed the title Fix doc embedded lite app Fix the embedded Lite apps in the docs Feb 3, 2025
@abidlabs
Copy link
Member

abidlabs commented Feb 3, 2025

I assume this is ready for a review @whitphx?

@abidlabs abidlabs marked this pull request as ready for review February 3, 2025 17:56
@whitphx
Copy link
Member Author

whitphx commented Feb 4, 2025

You are right, sorry I forgot to switch the state.

@aliabd
Copy link
Collaborator

aliabd commented Feb 4, 2025

@whitphx 6bb14ca is fine but the other refactoring doesn't work. I think its a race condition and the lite.js gets loaded after the lite element is added to the dom, which makes it miss it somehow. You can see this here: https://eeca3c64.gradio-website.pages.dev/main/docs/gradio/interface#demos (refresh a couple of times) But that's why i did it in the afterNavigate

@whitphx
Copy link
Member Author

whitphx commented Feb 5, 2025

@aliabd Thank you!
Now I think we should keep this refactoring and fix lite.js to work in this situation because such a race condition can be a trouble when Lite is used as a library by community users and it shouldn't require them to take care of loading timing. I will try it.

@whitphx
Copy link
Member Author

whitphx commented Feb 6, 2025

CleanShot 2025-02-06 at 16 24 22@2x
The custom component is loaded and the worker is started, but the view is not mounted properly.


And the element is already mounted as a custom element.

GradioLite = window.customElements.get("gradio-lite") //class t extends HTMLElement{controller=null;connectedCallback(){window.requestAnimationFrame(()=>{const i=this.parseGradioComponentOptions(),s=this.parseGradioLiteAppOptions();this.innerHTML="",this.contro…
el = document.getElementsByTagName("gradio-lite")[0] //<gradio-lite playground shared-worker layout=​"vertical" class=​"p-2">​…​</gradio-lite>​flex
el instanceof GradioLite // true

The following error message is displayed uniquely when this problem happens: Update: It was not true.

[Deprecation] Custom state pseudo classes have been changed from ":--color-var" to ":state(color-var)". See more here: <URL>

Error

CleanShot 2025-02-06 at 17 41 02@2x

Normal

CleanShot 2025-02-06 at 17 41 28@2x

Normal with this error

CleanShot 2025-02-06 at 17 52 46@2x


My current hypothesis is this error occurs when svelte.js is loaded after lite.js.

  • It always occurs on local dev (pnpm --filter website dev)
  • It disappears if <script src="http://localhost:8000/dist/lite.js" type="module"></script> in Demos.svelte is replaced with
    	<script type="module">
      	setTimeout(() => {
      		import("http://localhost:8000/dist/lite.js");
      	}, 1000);
      </script>

Tough to fix it now.

@whitphx
Copy link
Member Author

whitphx commented Feb 7, 2025

@aliabd Sorry i just reverted the second commit. Plz give a review.

Copy link
Collaborator

@aliabd aliabd left a comment

Choose a reason for hiding this comment

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

LGTM @whitphx, i think you're right that we should eventually fix this so users don't have to deal with it. but fair to do this in the future.

@abidlabs abidlabs enabled auto-merge (squash) February 11, 2025 18:58
@abidlabs
Copy link
Member

Awesome I'm going to enable auto-merge so we can get this for the release

@abidlabs abidlabs disabled auto-merge February 11, 2025 19:11
@abidlabs abidlabs merged commit a69c61c into main Feb 11, 2025
24 checks passed
@abidlabs abidlabs deleted the fix-doc-embedded-lite-app branch February 11, 2025 19:11
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.

4 participants