Skip to content

fix: getContext() should be sync #222

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

Merged
merged 2 commits into from
Nov 19, 2024
Merged

fix: getContext() should be sync #222

merged 2 commits into from
Nov 19, 2024

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Nov 19, 2024

Here are few follow ups from #216

Most important: getContext need to be sync not async (forgot to stage this in previous PR) and additionally we should check for Netlify global being defined (otherwsie Angular Dev doesn't work)
2nd most important: Make sure .d.ts files get packed, otherwise Angular Compiler will fail (by default) because of missing declarations

I'm also updating to newest RCs released few hours ago and applying some changes based on what changed between rc.2 and rc.3 (in our readme and in demo app)

@pieh pieh requested a review from a team as a code owner November 19, 2024 08:27
Copy link

netlify bot commented Nov 19, 2024

Deploy Preview for plugin-angular-universal-demo ready!

Name Link
🔨 Latest commit fd99910
🔍 Latest deploy log https://app.netlify.com/sites/plugin-angular-universal-demo/deploys/673c745a98e40200082adc85
😎 Deploy Preview https://deploy-preview-222--plugin-angular-universal-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Nov 19, 2024

```diff
+import { REQUEST, REQUEST_CONTEXT } from '@angular/ssr/tokens'
+import { REQUEST, REQUEST_CONTEXT } from '@angular/core'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ref angular/angular-cli#28871 - previous module was removed in @angular/ssr@19.0.0-rc.3

@Inject('netlify.request') @Optional() request?: Request,
@Inject('netlify.context') @Optional() context?: Context,
@Inject(REQUEST) @Optional() request?: Request,
@Inject(REQUEST_CONTEXT) @Optional() context?: Context,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to convert that in previous PR (netlify.request -> REQUEST) after setting up AppEngine, so this both moves that and use new place to get REQUEST and REQUEST_CONTEXT tokens from

@@ -7,6 +7,7 @@
"src/**/*.js",
"src/**/*.mjs",
"src/**/*.json",
"src/**/*.d.ts",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise https://github.com/netlify/angular-runtime/blob/main/src/common-engine.d.ts and https://github.com/netlify/angular-runtime/blob/main/src/context.d.ts wouldn't be packed for npm - it worked locally with demo and test fixtures because of package symlinking, but would result in something like below outside of the repo:

Application bundle generation failed. [4.128 seconds]

✘ [ERROR] TS7016: Could not find a declaration file for module '@netlify/angular-runtime/common-engine'. '/Users/misiek/test/angular-19-rnd-1/node_modules/@netlify/angular-runtime/src/common-engine.mjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/netlify__angular-runtime` if it exists or add a new declaration (.d.ts) file containing `declare module '@netlify/angular-runtime/common-engine';` [plugin angular-compiler]

    src/server.ts:2:23:
      2 │ import { render } from '@netlify/angular-runtime/common-engine'
        ╵                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@@ -1,2 +1,2 @@
// eslint-disable-next-line no-undef
export const getContext = async () => Netlify?.context
export const getContext = () => (typeof Netlify !== 'undefined' ? Netlify?.context : undefined)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The async was wrong and just result of copying boiler plate from other file. I did miss staging that change in previous PR, but other than that I also had to add check to see if global Netlify is defined, otherwise ng serve (Angular dev mode) would fail with:

ReferenceError: Netlify is not defined
    at Module.getContext (/Users/misiek/test/angular-19-rnd-2/.angular/cache/19.0.0-rc.3/angular-19-rnd-2/vite/deps_ssr/@netlify_angular-runtime_context.js?v=61c1d17e:1:1)
    at netlifyAppEngineHandler (/Users/misiek/test/angular-19-rnd-2/src/server.ts:9:19)
    at /Users/misiek/test/angular-19-rnd-2/node_modules/@angular/build/src/tools/vite/middlewares/ssr-middleware.js:83:38

orinokai
orinokai previously approved these changes Nov 19, 2024
Copy link

@orinokai orinokai left a comment

Choose a reason for hiding this comment

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

All looks 👍🏼 to me

@pieh pieh merged commit 1cb569c into main Nov 19, 2024
11 checks passed
@pieh pieh deleted the fix/angular-19-follow-up branch November 19, 2024 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants