-
Notifications
You must be signed in to change notification settings - Fork 439
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
Restrict Angular SSR to paths in the sitemap #3682
base: main
Are you sure you want to change the base?
Conversation
Tests are failing because CI is checking for SSR on
The first option is probably the best because https://demo.dspace.org/entities/person/3b087e38-cd6b-4d85-9409-99a9f6f03425?spc.page=1&query=search With entity search pages we have many combinations of pages depending on filters and number of items similar to Perhaps this requires a re-think. What about inverting the logic and enabling SSR for everything, but disabling it on certain paths? |
|
@alanorth : Thank you so much for getting this PR created! I was just asking someone to do this in yesterday's Developers Meeting. Regarding the failing tests, I'd recommend adding One other suggestion. I think it'd be better to make these paths configurable instead of hardcoding them in the
(You'd have to update the existing Then in the code use I'd argue that there also should be a way to enable SSR for everything (to retain current behavior). Perhaps that's the default behavior if this Overall, I do like this PR & support adding it quickly. I just want to add more flexibility to the configuration, as there's a chance that different sites will want to add additional paths (or keep the default behavior of SSR enabled for every path). |
You're welcome. I saw the meeting notes and was surprised that there wasn't already a PR, since I've been using versions of this patch for a few months already.
Yes, agreed.
Oh good idea, I didn't know about |
3d544f6
to
ccd0449
Compare
I've updated this to use a configurable array of paths, including Duplicating the configuration of the |
ccd0449
to
34c38b6
Compare
Hi @alanorth, |
34c38b6
to
eeccff2
Compare
@alanorth This PR looks good. To make the paths list more easily configurable, would it make more sense to add them to the dspace-angular/config/config.example.yml Lines 20 to 26 in f24e53f
|
@nwoodward I wasn't sure about the interaction between these defaults. I think the ones in |
@alanorth : To answer your question, the Any settings you set in your That said, I would also recommend we add this setting to the |
Great, thanks @tdonohue. I will add the SSR paths to |
eeccff2
to
1174068
Compare
Thanks for the feedback 🙇 . I've updated the patch to use the |
Thanks @alanorth! Everything looks good. I'm running into an issue testing it that may be due to my ignorance about how SSR and CSR work. I'm trying to test it locally on I tested all the paths on the list, and they all were rendered by SSR. Then I removed |
@nwoodward I only tested in production mode with Also, it helps to enable |
@nwoodward : @alanorth is correct. SSR only works if you are running in Production Mode. (See how to do that in that README link. To do Production mode on 8.x/7.x you need to use The best way to test SSR is by starting the UI in production mode on localhost:4000, access it, and then turn off Javascript in your Browser. For example: https://developer.chrome.com/docs/devtools/javascript/disable With Javascript disabled, you can ONLY see parts of the User Interface that have gone through SSR. Essentially, you are browsing the site like a crawler would. All links/buttons should work, and SSR pages should load properly. However, anything that requires Javascript (e.g. some animations or dropdowns) or CSR will not work. You could test this PR by comparing it to the https://sandbox.dspace.org. The Sandbox will use SSR on every page, while this PR should not (so some pages should not load with Javascript disabled) |
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.
@alanorth : I gave this a test today. Mostly it's working great. I can verify that paths not listed in the new ssr.paths
configuration do not undergo SSR (the pages just appear blank when Javascript is disabled). Conversely, those path listed in that configuration are all undergoing SSR... so the page will still load the main content with Javascript disabled.
However, I've found a small bug in the logic for the homepage when Javascript is disabled. If you access the homepage via http://localhost:4000/home, then it loads via SSR. However, if you access it via http://localhost:4000/ then it will not load (because the root path doesn't undergo SSR).
I think we may want to see if there's a way to simply hardcode that the root path (/) always undergoes SSR. I initially tried adding '/'
to the list of ssr.paths
, but that causes all paths to use SSR, because startsWith('/')
will always pass for every path.
We may need to add an "OR" clause next to the startsWith
logic in server.ts
which checks if it's the root path (/
), and if so, executes SSR.
Because Angular SSR is not very efficient, after discussion with the Google Scholar team we realized a compromise would be to only use SSR for pages in the DSpace sitemap (and the home page).
1174068
to
451b262
Compare
Thanks @tdonohue! Good catch. I added an explicit check for request to the root path: if (environment.ssr.enabled && req.method === 'GET' && (req.path === '/' || environment.ssr.paths.some(pathPrefix => req.path.startsWith(pathPrefix)))) {
... I tested and it's working with curl and with Javascript disabled in the browser for requests to the root. |
References
Description
Only enable Angular SSR for paths in the DSpace sitemap and the home page. This is a compromise after analyzing high CPU usage in DSpace 7+ and discussion with the Google Scholar team. We do not need to be wasting CPU and memory to generate and store SSR pages in the cache for request paths that are not "primary" DSpace objects, for example search and browse—these request paths contain data derived from the primary objects themselves and bots can spend endless time crawling them.
This solution was originally proposed by @vitorsilverio in #3110 (comment).
Some notes:
inlineCriticalCss
because it improves the user experience. We disabled it in DSpace 7.6.2 and 8.1 because it made SSR perform even more poorlyInstructions for Reviewers
Please add a more detailed description of the changes made by your PR. At a minimum, providing a bulleted list of changes in your PR is helpful to reviewers.
List of changes in this PR:
Include guidance for how to test or review your PR.
Try browsing the repository to see if all pages work as expected.
Checklist
This checklist provides a reminder of what we are going to look for when reviewing your PR. You do not need to complete this checklist prior creating your PR (draft PRs are always welcome).
However, reviewers may request that you complete any actions in this list if you have not done so. If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!
main
branch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lint
npm run check-circ-deps
)package.json
), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.