stephanrauh / ngx-extended-pdf-viewer

A full-blown PDF viewer for Angular 16, 17, and beyond
https://pdfviewer.net
Apache License 2.0
469 stars 176 forks source link

Add latest features to the SSR components #1622

Closed stephanrauh closed 1 year ago

stephanrauh commented 1 year ago

A couple of features of the library didn't make it into the server side rendering component yet:

AlexanderFalconi commented 1 year ago

Thanks! Deployed updates to our site (www.ournevadajudges.com) in the meantime using the prior version. Here's an example of your awesome library in action: https://www.ournevadajudges.com/judges/linda-marie-bell/cases?state=%7B%22show%22:%2250529-84697.pdf%22%7D Thanks Stephen!

stephanrauh commented 1 year ago

Awesome! I believe your site is a nice addition to the gallery I'm planning (see https://github.com/stephanrauh/ngx-extended-pdf-viewer/discussions/780). I just wonder why someone would want to rate a judge, and whether it's a good or even legal thing to do so. But I guess things are a bit different in the USA. Are you electing your judges in a public voting?

stephanrauh commented 1 year ago

Another question: I faintly remember you talked about a pull request (or was it someone else? I'm not sure). I just don't see any pull request, apart from the usual dependabot PRs. Did you forget to push it?

AlexanderFalconi commented 1 year ago

I would answer your rate-a-judge question but I don't need to, because our website doesn't track this information. If you're seeing judicial review and that is confusing you, it is occurring by our Supreme Court and disciplinary bodies. These are official government actions. If a judge makes a mistake, the Supreme Court corrects it by admonishing the judge and sending them instructions to correct the error. Yes, in Nevada, our judges are elected publicly.

AlexanderFalconi commented 1 year ago

I didn't create a pull request, but next time I will.

stephanrauh commented 1 year ago

That's interesting! It's always interesting to learn the ways of a foreign culture, and it's a surprising privilege that maintaining an open-source project turns out to provide plenty of opportunities for that. Come to think of it, our judical reviews probably work in a similar way, it's just something most of us never hear or think about.

AlexanderFalconi commented 1 year ago

Indeed, I've been sharing this with a lot of organizations to show appreciation for how your work impacts public service. You can also check out some videos of the judges actually coming to our private studio! https://youtu.be/gpPVgggGOCg And here's an example of our Supreme Court acknowledging our work: https://www.ournevadajudges.com/assets/docs/documents/35-order-granting-media-request.pdf I'm a software engineer and I think its important for us to find ways to serve the public with our talents, and I like to share this with other engineers.

stephanrauh commented 1 year ago

Mind blown!

stephanrauh commented 1 year ago

You've sort of summarized what's driving open-source developers like me. Your website probably isn't open-source, but you make it sound like a similar motivation. One day or another, I'm writing an article about that. That's a project I promised to a magazine editor years ago. In the meantime, he's left the company, but the idea is still there. :)

AlexanderFalconi commented 1 year ago

I have to keep this project private because of efforts by undermining factions who do not benefit from the public learning of how the judiciary operates. We have 3 lawyers, including 2 of which are with the American Civil Liberties Union. You can learn more about the ACLU's backing here: https://www.youtube.com/watch?v=6MAgYSVF1Ww It's disappointing to have to deal with this political aspect of our work but it is to be expected. You can also learn about our media support here: https://www.reviewjournal.com/opinion/editorials/editorial-new-family-court-rule-is-an-affront-to-justice-2606110/ and finally, you can learn about the Legal Aid Coalition's backing of us here: https://www.ournevadajudges.com/assets/docs/documents/359-brief-of-amici-curiae.pdf For these several reasons, I have to keep the project private, at least for now.

stephanrauh commented 1 year ago

Your bugfix has landed with version 15.2.2. At the moment, I don't have a SSR project at hand. Would you mind to run a quick check and tell me whether the bug is gone?

Thanks in advance, Stephan

AlexanderFalconi commented 1 year ago

I ran a quick check and, oddly enough, it compiles successfully but is still finding a window reference at run time. I first thought maybe it's something on my end, but when I revert to 15.1.~ it works fine, so it has to be something within the library. I don't even have a hunch with this one, since the stack trace purports the issue to be a reference to a css file (totally mystified on that).

ReferenceError: window is not defined at Module.5531 (../src/oxxj/css/index.css:3:1) at null.__webpack_require__ (../src/oxxj/css/index.css:3:1)

On Tue, Dec 13, 2022 at 12:48 PM Stephan Rauh @.***> wrote:

Your bugfix has landed with version 15.2.2. At the moment, I don't have a SSR project at hand. Would you mind to run a quick check and tell me whether the bug is gone?

Thanks in advance, Stephan

— Reply to this email directly, view it on GitHub https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues/1622#issuecomment-1349670385, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIRCAFHKNJHAO2GR6SJU5I3WNDOK7ANCNFSM6AAAAAAS3R76YE . You are receiving this because you commented.Message ID: @.***>

stephanrauh commented 1 year ago

Yeah, this rings a bell. It's been a while since I solved the last SSR bug, but I remember it was something to do with the non-existing window reference. The general wisdom is to use globalThis instead of window, but I'm not sure that's the correct solution in this particular case.

stephanrauh commented 1 year ago

My article on the topic: https://www.beyondjava.net/detecting-service-worker

stephanrauh commented 1 year ago

Testing !!globalThis['print'] probably does the trick. It should be false in SSR environment and true in a browser, unless someone assigns undefined to window.print - but that sounds like a pathological case, anyways.

AlexanderFalconi commented 1 year ago

I'll review your article. SSR can be so pesky.

On Tue, Dec 13, 2022 at 2:06 PM Stephan Rauh @.***> wrote:

Testing !!globalThis['print'] probably does the trick. It should be false in SSR environment and true in a browser, unless someone assigns undefined to window.print - but that sounds like a pathological case, anyways.

— Reply to this email directly, view it on GitHub https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues/1622#issuecomment-1349845944, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIRCAFG7RW4ZS75FIQBKH4DWNDXONANCNFSM6AAAAAAS3R76YE . You are receiving this because you commented.Message ID: @.***>

stephanrauh commented 1 year ago

@AlexanderFalconi Is your topic still open?

AlexanderFalconi commented 1 year ago

I'll try your latest version again this evening. By the way, a few days ago the Supreme Court is hearing arguments on the website (specifically First Amendment access). It's going to be streamed live. It's rare to get a Supreme Court to order oral arguments in a case. All 7 Justices will be fielding questions to government and ACLU lawyers. https://www.ournevadajudges.com/assets/docs/documents/407-order-scheduling-oral-argument.pdf

On Sun, Feb 5, 2023 at 12:54 PM Stephan Rauh @.***> wrote:

@AlexanderFalconi https://github.com/AlexanderFalconi Is your topic still open?

— Reply to this email directly, view it on GitHub https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues/1622#issuecomment-1418262005, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIRCAFATAYZOAWB6U45JZOLWWAHQNANCNFSM6AAAAAAS3R76YE . You are receiving this because you were mentioned.Message ID: @.***>

stephanrauh commented 1 year ago

I have a hard time to understand because I'm missing some context (not to mention the judical language - I'm not a native speaker of English). I doesn't read like somebody has sued you. Have you started a petition, and now they want to talk about it with you in person?

stephanrauh commented 1 year ago

BTW, I've released version 16.0.0 a few minutes ago. I believe it's a major improvement over version 15.

AlexanderFalconi commented 1 year ago

Yes, I used the website to teach the public about the courts, one of the Districts tried to put a stop to it, I brought it to the Supreme Court's attention with the help of American Civil Liberties Union lawyers, and they want to discuss it in person, before the public in their courtroom, which will be broadcast live. The lawyers of the ACLU will be speaking with them on my behalf. The government is sending 2 lawyers which will be expected to explain why they have done what they have done. If the Supreme Court rejects the government's position, it will cause a shockwave of change throughout the state and encourage other organizations like mine to teach the public.

I'm excited to try out 16. I'm hoping that one day I won't have to keep sending up a big chunk of folders from node_modules as well, this library is the only one where I have to do that.

On Sun, Feb 5, 2023 at 1:10 PM Stephan Rauh @.***> wrote:

I have a hard time to understand because I'm missing some context (not to mention the judical language - I'm not a native speaker of English). I doesn't read like somebody has sued you. Have you started a petition, and now they want to talk about it with you in person?

— Reply to this email directly, view it on GitHub https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues/1622#issuecomment-1418265791, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIRCAFGXUP2G2GIUHAWS6WTWWAJNTANCNFSM6AAAAAAS3R76YE . You are receiving this because you were mentioned.Message ID: @.***>

stephanrauh commented 1 year ago

Good luck! You convinced me that your website is for the public benefit, so I don't want it to go away.

From a German point of view, it sounds a bit odd because we value data protection highly, but then, we don't vote our judges. Our politicians enjoy very little privacy, so I guess that's the better comparison.

stephanrauh commented 1 year ago

As for sending a big chunk of folders: what's really important (from the user's point of view) is how much data is transferred to their device. That's a lot, but gzip or Brotli reduce the penalty to roughly half a megabyte. If you want to reduce the size of the installation: you can fine-tune what you copy to your assets folder. For instance, you probably don't need all the i18n files. I just tell people to copy them because that's the easiest way to get started.

AlexanderFalconi commented 1 year ago

It looks like 16 still breaks with SSR. It gives some kind of nebulous error regarding the first css file it tries to load. I reverted to 15.1.1 and everything works.

On Sun, Feb 5, 2023 at 1:33 PM Stephan Rauh @.***> wrote:

As for sending a big chunk of folders: what's really important (from the user's point of view) is how much data is transferred to their device. That's a lot, but gzip or Brotli reduce the penalty to roughly half a megabyte. If you want to reduce the size of the installation: you can fine-tune what you copy to your assets folder. For instance, you probably don't need all the i18n files. I just tell people to copy them because that's the easiest way to get started.

— Reply to this email directly, view it on GitHub https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues/1622#issuecomment-1418270719, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIRCAFHIXJXQ2OIGHA24OKDWWAMCVANCNFSM6AAAAAAS3R76YE . You are receiving this because you were mentioned.Message ID: @.***>

stephanrauh commented 1 year ago

@AlexanderFalconi Finally, I've managed to address your issue. I'm not entirely sure because the error I've fixed has nothing to do with CSS, but I'm positive version 16.2.1 knows how to do server-side rendering again.

I also plan to migrate the showcase (and later, my blog) to SSR. This blog article indicates I don't need a real server to do SSR. I always suspected pre-rendering does the trick, but until now, I wasn't able to figure out how to do it. I hope it works because buying an AWS EC2 instance is too expensive for a hobbyist open-source project!

Be that as it may, the point I want to bring home is that if everything works according to the plan, problems with server-side rendering are going to be a thing of the past because SSR is a first-class citizen in ngx-extended-pdf-viewer country.

AlexanderFalconi commented 1 year ago

Whatever you did, worked! It took me a while to get back because of this: https://www.reviewjournal.com/news/politics-and-government/nevada/supreme-court-weighs-arguments-challenging-closure-of-family-court-hearings-2737941/

And this: https://www.youtube.com/watch?v=4AbZmTCmuNI

On Mon, Feb 27, 2023 at 1:34 PM Stephan Rauh @.***> wrote:

@AlexanderFalconi https://github.com/AlexanderFalconi Finally, I've managed to address your issue. I'm not entirely sure because the error I've fixed has nothing to do with CSS, but I'm positive version 16.2.1 knows how to do server-side rendering again.

I also plan to migrate the showcase (and later, my blog) to SSR. This blog article https://levelup.gitconnected.com/prerender-angular-and-deploy-it-as-a-static-website-on-aws-s3-to-make-it-42-times-faster-115fadcf8614 indicates I don't need a real server to do SSR. I always suspected pre-rendering does the trick, but until now, I wasn't able to figure out how to do it. I hope it works because buying an AWS EC2 instance is too expensive for a hobbyist open-source project!

Be that as it may, the point I want to bring home is that if everything works according to the plan, problems with server-side rendering are going to be a thing of the past because SSR is a first-class citizen in ngx-extended-pdf-viewer country.

— Reply to this email directly, view it on GitHub https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues/1622#issuecomment-1447128145, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIRCAFBM4ZAEVJ3VGDUFTF3WZUMXTANCNFSM6AAAAAAS3R76YE . You are receiving this because you were mentioned.Message ID: @.***>

stephanrauh commented 1 year ago

Interesting links. Thanks for sharing!

As for ngx-extended-pdf-viewer: I'm happy to learn my library knows about SSR again. I'm trying to convert the showcase to server-side rendering, but that turned out to be difficult. As a first step, I've tried and manage to convert my blog to SSR. As things go, there are a couple of pages I forgot - especially those pages using the PDF viewer.

Be that as it may, I hope to succeed sooner or later. When I do, SSR problems are a thing of the past. Basically, that's one of the reasons for creating the showcase: it's great for testing.

stephanrauh commented 1 year ago

May I close this ticket now?

AlexanderFalconi commented 1 year ago

Sure!

On Thu, Mar 16, 2023 at 2:19 PM Stephan Rauh @.***> wrote:

Closed #1622 https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues/1622 as completed.

— Reply to this email directly, view it on GitHub https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues/1622#event-8772197432, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIRCAFDF2IP2EC6N64JPQPDW4N7V3ANCNFSM6AAAAAAS3R76YE . You are receiving this because you were mentioned.Message ID: <stephanrauh/ngx-extended-pdf-viewer/issue/1622/issue_event/8772197432@ github.com>

stephanrauh commented 1 year ago

@AlexanderFalconi Currently, I'm activating SSR on my blog. It shows a couple of presentations displayed by ngx-extended-pdf-viewer. You've got more experience with SSR than I have. I wonder if it's better to simply hide the component or too send the HTML even though the CSS is missing. What's your opinion?

The initial reponse of the server renders like so:

grafik

Not exactly easy to the eye, but on the plus side, it gives Google a lot of insight into what the page does.

The client-side rendering looks a bit nicer:

grafik
stephanrauh commented 1 year ago

BTW, version 16.2.8 allows you to use SSR without having to use the dedicated server module. I couldn't find out how to implement lazy loading with different modules on the client and on the server. I reckon that's a shortcoming of Angular which requires modules and imports to be static.

Now you can import NgxExtendedPdfViewerModule in a lazy-loaded child module and still benefit from SSR.

stephanrauh commented 1 year ago

It doesn't work yet - there's a problem with injecting the CSS theme. Stay tuned!