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: vscode fails to load scripts from _solara/cdn #763

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/solara-enterprise/solara_enterprise/search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ class SearchWidget(ipyvue.VueTemplate):
query = traitlets.Unicode("", allow_none=True).tag(sync=True)
search_open = traitlets.Bool(False).tag(sync=True)
failed = traitlets.Bool(False).tag(sync=True)
cdn = traitlets.Unicode(None, allow_none=True).tag(sync=True)

@traitlets.default("cdn")
def _cdn(self):
import solara.settings

if not solara.settings.assets.proxy:
return solara.settings.assets.cdn


@solara.component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ module.exports = {
return base
},
getCdn() {
return window.solara ? window.solara.cdn : `${this.getJupyterBaseUrl()}_solara/cdn`;
return this.cdn || (window.solara ? window.solara.cdn : `${this.getJupyterBaseUrl()}_solara/cdn`);
},
}
}
Expand Down
8 changes: 8 additions & 0 deletions solara/components/echarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class EchartsWidget(ipyvuetify.VuetifyTemplate):
on_mouseout = traitlets.Callable(None, allow_none=True)
# same, for performance
on_mouseout_enabled = traitlets.Bool(False).tag(sync=True)
cdn = traitlets.Unicode(None, allow_none=True).tag(sync=True)

@traitlets.default("cdn")
def _cdn(self):
import solara.settings

if not solara.settings.assets.proxy:
return solara.settings.assets.cdn

def vue_on_click(self, data):
if self.on_click is not None:
Expand Down
2 changes: 1 addition & 1 deletion solara/components/echarts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module.exports = {
return base;
},
getCdn() {
return window.solara ? window.solara.cdn : `${this.getJupyterBaseUrl()}_solara/cdn`
return this.cdn || (window.solara ? window.solara.cdn : `${this.getJupyterBaseUrl()}_solara/cdn`);
},
},
};
Expand Down
9 changes: 9 additions & 0 deletions solara/components/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ def _markdown_template(
html,
style="",
):
cdn = None
import solara.settings

if not solara.settings.assets.proxy:
cdn = solara.settings.assets.cdn

template = (
"""
<template>
Expand All @@ -89,6 +95,9 @@ def _markdown_template(
<script>
module.exports = {
async mounted() {
this.cdn = """
+ (rf"'{cdn}'" if cdn is not None else r"null")
+ r""";
await this.loadRequire();
this.mermaid = await this.loadMermaid();
this.mermaid.init();
Expand Down
8 changes: 8 additions & 0 deletions solara/components/markdown_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class MarkdownEditorWidget(ipyvuetify.VuetifyTemplate):

value = traitlets.Unicode("").tag(sync=True)
height = traitlets.Unicode("180px").tag(sync=True)
cdn = traitlets.Unicode(None, allow_none=True).tag(sync=True)

@traitlets.default("cdn")
def _cdn(self):
import solara.settings

if not solara.settings.assets.proxy:
return solara.settings.assets.cdn


@solara.component
Expand Down
2 changes: 1 addition & 1 deletion solara/components/markdown_editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ module.exports = {
return base
},
getCdn() {
return window.solara ? window.solara.cdn : `${this.getJupyterBaseUrl()}_solara/cdn`;
return this.cdn || (window.solara ? window.solara.cdn : `${this.getJupyterBaseUrl()}_solara/cdn`);
},
},
};
Expand Down
8 changes: 8 additions & 0 deletions solara/components/sql_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ class SqlCodeWidget(ipyvue.VueTemplate):
query = traitlets.Unicode(allow_none=True, default_value=None).tag(sync=True)
tables = traitlets.Dict(allow_none=True, default_value=None).tag(sync=True)
height = traitlets.Unicode("180px").tag(sync=True)
cdn = traitlets.Unicode(None, allow_none=True).tag(sync=True)

@traitlets.default("cdn")
def _cdn(self):
import solara.settings

if not solara.settings.assets.proxy:
return solara.settings.assets.cdn


@solara.component
Expand Down
2 changes: 1 addition & 1 deletion solara/components/sql_code.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
return base
},
getCdn() {
return window.solara ? window.solara.cdn : `${this.getJupyterBaseUrl()}_solara/cdn`;
return this.cdn || (window.solara ? window.solara.cdn : `${this.getJupyterBaseUrl()}_solara/cdn`);
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion solara/widgets/vue/gridlayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = {
return base
},
getCdn() {
return window.solara ? window.solara.cdn : `${this.getJupyterBaseUrl()}_solara/cdn`;
return this.cdn || (window.solara ? window.solara.cdn : `${this.getJupyterBaseUrl()}_solara/cdn`);
},
}
}
Expand Down
8 changes: 8 additions & 0 deletions solara/widgets/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class GridLayout(v.VuetifyTemplate):
grid_layout = traitlets.List(default_value=cast(List[Dict], [])).tag(sync=True)
draggable = traitlets.CBool(True).tag(sync=True)
resizable = traitlets.CBool(True).tag(sync=True)
cdn = traitlets.Unicode(None, allow_none=True).tag(sync=True)

@traitlets.default("cdn")
def _cdn(self):
import solara.settings

if not solara.settings.assets.proxy:
return solara.settings.assets.cdn


class HTML(v.VuetifyTemplate):
Expand Down
Loading