Skip to content
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

GCDS- POC header #4281

Closed
wants to merge 2 commits into from
Closed

GCDS- POC header #4281

wants to merge 2 commits into from

Conversation

timarney
Copy link
Member

@timarney timarney commented Sep 17, 2024

Summary | Résumé

POC using GCDS Header

#4273

@timarney
Copy link
Member Author

timarney commented Sep 17, 2024

Won't compile

 GET /en/sla?_rsc=bcp9r 200 in 1743ms
TypeError: Cannot read properties of undefined (reading 'split')
    at Object.read (webpack-internal:///(ssr)/./node_modules/i18next-browser-languagedetector/dist/esm/i18nextBrowserLanguageDetector.js:92:30)
    at Object.lookup (webpack-internal:///(ssr)/./node_modules/i18next-browser-languagedetector/dist/esm/i18nextBrowserLanguageDetector.js:109:22)
  Compiling /api/auth/[...nextauth] ...
  ./node_modules/linkedom/commonjs/canvas.cjs
Module not found: Can't resolve 'canvas' in '/Users/timarney/projects/platform-forms-client/node_modules/linkedom/commonjs'

Import trace for requested module:
./node_modules/linkedom/commonjs/canvas.cjs
./node_modules/linkedom/esm/html/canvas-element.js
./node_modules/linkedom/esm/shared/html-classes.js
./node_modules/linkedom/esm/index.js
./node_modules/@cdssnc/gcds-components-react-ssr/dist/esm/lib/server.js
./app/layout.tsx
 GET /api/auth/session 200 in 2707ms
[08:26:06.824] WARN: NextAuth warning - Code: debug-enabled

Related to:

Server.js

var import_linkedom = require("linkedom");

@timarney
Copy link
Member Author

@ethanWallace @daine

Any thoughts on how to get around the linkedom issue above?

I can see the same errors throwing on this example but in this case it does render the header.

https://codesandbox.io/p/devbox/hyzfcx

@ethanWallace
Copy link

@timarney You should be able to add this bit to your next.config.

  webpack: (config) => {
    // Fixes dependency issues with `canvas` and `perf_hooks` of linkedom
    config.resolve.fallback = { canvas: false, perf_hooks: false };

    return config;
  },

@timarney
Copy link
Member Author

timarney commented Sep 17, 2024

Thanks @ethanWallace ---

Hitting a further issue

  uncaughtException: TypeError: Cannot read properties of undefined (reading 'split')
    at Object.read (webpack-internal:///(ssr)/./node_modules/i18next-browser-languagedetector/dist/esm/i18nextBrowserLanguageDetector.js:92:30)
Screenshot 2024-09-17 at 9 05 51 AM

@timarney
Copy link
Member Author

Pushed a commit comment out the lang detect for now.

Copy link
Contributor

@timarney
Copy link
Member Author

timarney commented Sep 18, 2024

With workarounds in place we're able to get a component rendering.

Screenshot 2024-09-18 at 7 42 28 AM

@timarney
Copy link
Member Author

@ethanWallace have you folks looked at nonces yet?

https://stenciljs.com/docs/csp-nonce

Our CSP is very strict
Screenshot 2024-09-18 at 8 15 44 AM

@timarney
Copy link
Member Author

Having done some initial investigation into feasibility we have 2 initial blockers

@ethanWallace
Copy link

@timarney We haven't explored how a team could use that nonce helper function yet.

@timarney
Copy link
Member Author

Closing this PR as it was only for feasibility check per #4273

Thanks for the help @ethanWallace

@timarney timarney closed this Sep 18, 2024
@daine
Copy link
Contributor

daine commented Sep 25, 2024

@timarney could you send a few info my way around your setup on nonces? We have CSP as well but haven't implemented the nonce method but it's something we can look at. I'd be curious to know the implementation details that you have around it.

Update: I created issues on our github repo linking back to this PR. If you have anything to add or share you can add it to those issues as well. Thanks for giving it a shot!

@timarney
Copy link
Member Author

timarney commented Sep 26, 2024

@daine for the nonce

It might be possible if the setNonce function was exposed we might be able to set it as we do have the ability to pass the generated nonce to components i.e. on the Form Ownership we pass the nonce to React Select / Emotion. There's further issues with the nonce on our end but noting that's how we've done it for other libs.

  const { session, ability } = await authCheckAndThrow().catch(() => ({
    session: null,
    ability: null,
  }));
...
  const nonce = await getNonce();


    return (
      <ManageForm
        nonce={nonce}
export const FormOwnership = ({
  nonce,
const cache: EmotionCache = createCache({
    key: "gc-forms",
    nonce: nonce || "xyz123",
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants