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

pass container element to iframe stamper #183

Merged
merged 5 commits into from
Dec 13, 2023
Merged

Conversation

oliviathet
Copy link
Contributor

Summary & Motivation

  • Use container element instead of id for iframe stamper constructor. This allows for the iframe stamper to be appended onto an element in the shadow DOM.
  • Update auth, recovery, export examples.
  • Bump turnkey/iframe-stamper package major version.

How I Tested These Changes

  • locally ran auth, recovery, export examples

Did you add a changeset?

If updating one of our packages, you'll likely need to add a changeset to your PR. To do so, run pnpm changeset. pnpm changeset will generate a file where you should write a human friendly message about the changes. Note how this (example) includes the package name (should be auto added by the command) along with the type of semver change (major.minor.patch) (which you should set).

These changes will be used at release time to determine what packages to publish and how to bump their version. For more context see this comment.

Copy link

codesandbox-ci bot commented Dec 7, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@oliviathet
Copy link
Contributor Author

also, i think the test we have in packages/iframe-stamper/src/__tests__/iframe-test.ts is irrelevant now because we're directly passing the html element now. will rewrite this test.

);
}
this.container = container;
this.container = config.iframeContainer;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the check above (on line 64) needs to be updated, from document.getElementById(config.iframeElementId) to this.container.querySelector(`#${config.iframeElement}`)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👀 👀 Fixed, thanks!

);
}
this.container = container;
this.container = config.iframeContainer;
Copy link
Contributor

Choose a reason for hiding this comment

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

Separately: do we need to check for config.iframeContainer !== undefined? Or is it already implicit if the type is HTMLElement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Looked into this and the document.getElementById and document.querySelector both return HTMLElement | null when the element's not found. However, they can return undefined when they're accessed before the element is created. In short, yep I added this check. Thanks!

@@ -5,42 +5,19 @@ import { IframeStamper } from "@turnkey/iframe-stamper";
import * as React from "react";
import { useEffect, useState } from "react";
import axios from "axios";
import { Export } from "@/components/Export";
Copy link
Contributor

Choose a reason for hiding this comment

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

Clean!! ❤️

Comment on lines 34 to 39
if (!iframeStamper) {
const iframeContainer = document.getElementById(TurnkeyIframeContainerId);
if (!iframeContainer) {
console.error(`Cannot create iframe stamper: no container with ID ${TurnkeyIframeContainerId} exists`);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still necessary given the component is in control of creating / inserting the container into the DOM?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this check here since I made the change above allowing for iframeContainer to be passed as null/undefined and the check is done in the iframe stamper's constructor now.

@oliviathet oliviathet requested a review from r-n-o December 13, 2023 16:30
Copy link
Contributor

@r-n-o r-n-o left a comment

Choose a reason for hiding this comment

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

💯

@oliviathet oliviathet force-pushed the olivia/iframe-container branch from e42d182 to a71d6ed Compare December 13, 2023 19:41
@oliviathet oliviathet merged commit ef23b51 into main Dec 13, 2023
5 checks passed
@oliviathet oliviathet deleted the olivia/iframe-container branch December 13, 2023 19:44
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.

2 participants