Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Replace JSRender templating with vanilla js (resolves #30)#31

Merged
demiankatz merged 16 commits intoIIIF-Commons:masterfrom
anthonyhashemi:replace-jsrender-templating-with-vanilla-js
May 9, 2025
Merged

Replace JSRender templating with vanilla js (resolves #30)#31
demiankatz merged 16 commits intoIIIF-Commons:masterfrom
anthonyhashemi:replace-jsrender-templating-with-vanilla-js

Conversation

@anthonyhashemi
Copy link
Copy Markdown
Contributor

@anthonyhashemi anthonyhashemi commented Apr 8, 2025

Change:

Replace JSRender templating with vanilla js. Still need to import jsviews lib for the observable api, but that bit doesn't have the csp issue, only the views api/templating engine was a problem.

Reason:

See details of the CSP issue this is fixing here: #30

@anthonyhashemi anthonyhashemi force-pushed the replace-jsrender-templating-with-vanilla-js branch 3 times, most recently from 48b0933 to a380257 Compare April 10, 2025 10:22
@anthonyhashemi anthonyhashemi changed the title WIP | Replace JSRender templating with vanilla js Replace JSRender templating with vanilla js Apr 10, 2025
@anthonyhashemi
Copy link
Copy Markdown
Contributor Author

@demiankatz I have tested this locally by spinning up examples/index.html and making sure that was consistent with master. Also, propagated this change up to universalviewer and then my project locally and the csp issue is gone and UV in my project acts the same as before.

It looks like the GH actions / checks on this repo are broken (same on another open PR here) so I don't know if someone has time to fix those or whether this would be able to be merged in without them working? Is there a specific testing process before PRs get merged in?

Comment thread src/index.ts Outdated
Comment thread src/index.ts Outdated
@anthonyhashemi anthonyhashemi force-pushed the replace-jsrender-templating-with-vanilla-js branch 2 times, most recently from 8258ed1 to f7ef293 Compare April 10, 2025 10:40
@anthonyhashemi anthonyhashemi force-pushed the replace-jsrender-templating-with-vanilla-js branch from f7ef293 to da5ce72 Compare April 10, 2025 10:40
@anthonyhashemi anthonyhashemi force-pushed the replace-jsrender-templating-with-vanilla-js branch from 78ae390 to 6ed4078 Compare April 10, 2025 10:45
@demiankatz
Copy link
Copy Markdown
Contributor

Thanks, @anthonyhashemi -- it looks like the build failure here is related to @edsilv's Netlify deployment. I'm not sure why this is broken or if it is still needed. I will talk to him about it and see if I can get a green checkmark, but we should be able to merge this even if the build is technically failing.

In any case, I'll also try to find time to review and test this before too long!

Comment thread src/index.ts
Comment thread src/index.ts Outdated
@demiankatz
Copy link
Copy Markdown
Contributor

@anthonyhashemi, one thing that has me a little confused: where is JSRender even coming from in this project? I don't see it in the package.json or package-lock.json. Just wondering if there's some dependency we should remove now that this refactoring is complete. If there is, I sure don't see where -- but I'm a bit puzzled by the whole situation.

Comment thread src/index.ts
Comment thread src/index.ts
Comment thread src/index.ts Outdated
@anthonyhashemi
Copy link
Copy Markdown
Contributor Author

@demiankatz My understanding is that it is part of jsviews, which is imported with <script src="https://cdnjs.cloudflare.com/ajax/libs/jsviews/0.9.75/jsviews.min.js"></script> in examples/index.htnmml. You are right though it isn't part of the package.json. I see universal viewer does have it in its package.json so maybe it's just poorly documented in this repo but it does seem necessary; it is referenced in comments in the interfaces in src/globals.d.ts.

@anthonyhashemi, one thing that has me a little confused: where is JSRender even coming from in this project? I don't see it in the package.json or package-lock.json. Just wondering if there's some dependency we should remove now that this refactoring is complete. If there is, I sure don't see where -- but I'm a bit puzzled by the whole situation.

@anthonyhashemi
Copy link
Copy Markdown
Contributor Author

Thanks, @anthonyhashemi -- it looks like the build failure here is related to @edsilv's Netlify deployment. I'm not sure why this is broken or if it is still needed. I will talk to him about it and see if I can get a green checkmark, but we should be able to merge this even if the build is technically failing.

In any case, I'll also try to find time to review and test this before too long!

Thanks @demiankatz!

@demiankatz
Copy link
Copy Markdown
Contributor

@demiankatz My understanding is that it is part of jsviews, which is imported with <script src="https://cdnjs.cloudflare.com/ajax/libs/jsviews/0.9.75/jsviews.min.js"></script> in examples/index.htnmml. You are right though it isn't part of the package.json. I see universal viewer does have it in its package.json so maybe it's just poorly documented in this repo but it does seem necessary; it is referenced in comments in the interfaces in src/globals.d.ts.

Ahh, interesting! I wonder if we can now remove these references, since we have eliminated the dependency on the library. I also wonder if the jsviews component is used elsewhere in the upstream UV project, or if this was the only reason for it. I imagine if it's being used anywhere else, there may be further CSP issues to worry about.

@anthonyhashemi
Copy link
Copy Markdown
Contributor Author

anthonyhashemi commented Apr 10, 2025

@demiankatz My understanding is that it is part of jsviews, which is imported with <script src="https://cdnjs.cloudflare.com/ajax/libs/jsviews/0.9.75/jsviews.min.js"></script> in examples/index.htnmml. You are right though it isn't part of the package.json. I see universal viewer does have it in its package.json so maybe it's just poorly documented in this repo but it does seem necessary; it is referenced in comments in the interfaces in src/globals.d.ts.

Ahh, interesting! I wonder if we can now remove these references, since we have eliminated the dependency on the library. I also wonder if the jsviews component is used elsewhere in the upstream UV project, or if this was the only reason for it. I imagine if it's being used anywhere else, there may be further CSP issues to worry about.

We still need jsviews as we are still using jsobservable which is part of it https://www.jsviews.com/#jsobservable

We could maybe do work to remove that but I would prefer that be done in a separate PR to keep this PR focussed.

In terms of UV, from what I could see from my test, there was no longer a CSP issue when viewing images or pdfs. I can't be certain for other file types.

It seems to define a similar JSQuery interface as this repo referencing jsviews. It uses .view and .observable like this still does (note: I had replaced usage of .view thinking it was problematic but it is only the jsviews api https://www.jsviews.com/#jsviews which causes the issue so I brought it back)

@demiankatz
Copy link
Copy Markdown
Contributor

We still need jsviews as we are still using jsobservable which is part of it https://www.jsviews.com/#jsobservable

We could maybe do work to remove that but I would prefer that be done in a separate PR to keep this PR focussed.

Agreed, if we need it for more than just the templating, we shouldn't introduce scope creep to this PR!

Copy link
Copy Markdown
Contributor

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

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

Thanks, @anthonyhashemi, this looks good to me! See below for a couple of questions about escaping. Apologies if either or both are "false positives," but I want to be sure we don't introduce any subtle bugs.

Comment thread src/index.ts Outdated
Comment thread src/index.ts Outdated
@anthonyhashemi anthonyhashemi force-pushed the replace-jsrender-templating-with-vanilla-js branch 3 times, most recently from d05ef28 to e5133bd Compare April 28, 2025 13:54
@anthonyhashemi anthonyhashemi force-pushed the replace-jsrender-templating-with-vanilla-js branch from e5133bd to aa73e3c Compare April 28, 2025 13:56
Comment thread src/index.ts
Comment thread src/index.ts
@anthonyhashemi anthonyhashemi force-pushed the replace-jsrender-templating-with-vanilla-js branch from 6f230a5 to 65d03dc Compare April 28, 2025 15:58
Copy link
Copy Markdown
Contributor

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

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

Thanks, @anthonyhashemi! See below for a few minor type and optimization suggestions; apologies if any are incorrect or misguided. I haven't had a chance to do hands-on testing yet, but I'll do that after you've had a chance to address this review (and when I return from my conference).

Comment thread src/index.ts Outdated
Comment thread src/index.ts Outdated
Comment thread src/index.ts Outdated
Comment thread src/index.ts Outdated
@anthonyhashemi
Copy link
Copy Markdown
Contributor Author

Great suggestions @demiankatz . I have applied them (the types with a slight tweak) and it is still working properly.

Copy link
Copy Markdown
Contributor

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

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

Thanks again, @anthonyhashemi. This looks good to me and appears to be working on my end as well.

I'll leave this open for a few more days in case others want to share feedback. If I don't hear anything, I'll make the release and open a PR to integrate this new version of the gallery into the UV, so we can make sure it behaves as expected.

@demiankatz demiankatz changed the title Replace JSRender templating with vanilla js Replace JSRender templating with vanilla js (resolves #30) May 7, 2025
@anthonyhashemi
Copy link
Copy Markdown
Contributor Author

Thanks again, @anthonyhashemi. This looks good to me and appears to be working on my end as well.

I'll leave this open for a few more days in case others want to share feedback. If I don't hear anything, I'll make the release and open a PR to integrate this new version of the gallery into the UV, so we can make sure it behaves as expected.

Brilliant, thanks, looking forward to it. Let me know if I can help with anything re release / upstream integration

@demiankatz
Copy link
Copy Markdown
Contributor

As promised, this is now merged and released; here's the PR to integrate into UV: UniversalViewer/universalviewer#1406

@anthonyhashemi
Copy link
Copy Markdown
Contributor Author

Amazing @demiankatz , will take a look at that PR

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants