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
feat(interruptsource): allow interrupts to use an ssr option #130
Conversation
ssr option instructs interrupt sources to ignore targets derived from global context such as window or document so they can be safely used in ssr/universal apps. If you are using ssr/universal, do not use DEFAULT_INTERRUPTSOURCES. Instead, use `createDefaultInterruptSources({ssr: !isPlatformBrowser(platformId) })`. See docs or https://stackoverflow.com/a/46893433/64750 for information on how to use isPlatformBrowser. Fixes #77, #115
const target = | ||
options && (options as EventTargetInterruptOptions).ssr | ||
? null | ||
: document.documentElement; |
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.
I'm still getting the below compile error when I import NgIdleKeepaliveModule.forRoot()
in the app.module of my Angular project, and run the command npm run build:ssr && npm run serve:ssr
.
/Users/bfwg/code/ng2-idle-example/dist/server/main.js:112377
: document.documentElement;
^
ReferenceError: document is not defined
at new DocumentInterruptSource (/Users/bfwg/code/ng2-idle-example/dist/server/main.js:112377:15)
at createDefaultInterruptSources (/Users/bfwg/code/ng2-idle-example/dist/server/main.js:112522:9)
at Module.evxF (/Users/bfwg/code/ng2-idle-example/dist/server/main.js:112527:34)
at __webpack_require__ (/Users/bfwg/code/ng2-idle-example/dist/server/main.js:20:30)
at Object.V7fC (/Users/bfwg/code/ng2-idle-example/dist/server/main.js:97581:13)
at __webpack_require__ (/Users/bfwg/code/ng2-idle-example/dist/server/main.js:20:30)
at Object.K011 (/Users/bfwg/code/ng2-idle-example/dist/server/main.js:86964:37)
at __webpack_require__ (/Users/bfwg/code/ng2-idle-example/dist/server/main.js:20:30)
at Object.0 (/Users/bfwg/code/ng2-idle-example/dist/server/main.js:437:18)
at __webpack_require__ (/Users/bfwg/code/ng2-idle-example/dist/server/main.js:20:30)
main.js:112377
points to this line.
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.
Can you publish this example code somewhere?
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.
I made a ssr boilerplate app https://github.com/bfwg/ng2-idle-ssr-example.
Steps to reproduce:
- clone the ng2-idle-ssr-example app.
- npm install
- build
core
andkeepalive
module from thie PR. - cope them into the node_modules of the boilerplate app, inside
@ng-idle
- run
npm run build:ssr && npm run serve:ssr
command.
Please let me know if you need more information.
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.
@bfwg, did you find a solution to your problem? I am having similar errors to yours.
ssr option instructs interrupt sources to ignore targets
derived from global context such as window or document so
they can be safely used in ssr/universal apps.
If you are using ssr/universal, do not use
DEFAULT_INTERRUPTSOURCES. Instead, use
createDefaultInterruptSources({ssr: !isPlatformBrowser(platformId) })
.See docs or https://stackoverflow.com/a/46893433/64750
for information on how to use isPlatformBrowser.
Fixes #77, #115
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (check one with "x")
What is the current behavior? (You can also link to an open issue here)
No support for SSR/Universal apps.
What is the new behavior?
Adds an opt-in option when creating interrupt sources that will allow compatibility with SSR/universal.
Does this PR introduce a breaking change? (check one with "x")
If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...
Other information: