Skip to content

feat(elements): <Loading> component - #3002

Merged
LekoArts merged 42 commits into
mainfrom
lekoarts/sdk-1291-loading-states
Mar 20, 2024
Merged

feat(elements): <Loading> component#3002
LekoArts merged 42 commits into
mainfrom
lekoarts/sdk-1291-loading-states

Conversation

@LekoArts

@LekoArts LekoArts commented Mar 15, 2024

Copy link
Copy Markdown
Contributor

Description

Adds a <Loading> component. Access the loading state of a chosen scope. Scope can refer to a step, a provider, or the global loading state. The global loading state is true when any of the other scopes are loading.

Example:

const Page = () => {
  return (
    <SignIn>
      <Loading>
        {(isLoading) => isLoading && "Infers to scope='global'"}
      </Loading>
      <Step name="start">
        <Loading scope="provider:google">
          {(isLoading) => (
            <Provider name="google" disabled={isLoading}>
              {isLoading ? "Loading..." : "Continue with Google"}
            </Provider>
          )}
        </Loading>
        <Submit>
          <Loading>
            {(isLoading) => isLoading && "Infers to scope='step:start'"}
          </Loading>
        </Submit>
      </Step>
    </SignIn>
  )
}

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@LekoArts LekoArts added this to the @clerk/elements (Beta) milestone Mar 15, 2024
@changeset-bot

changeset-bot Bot commented Mar 15, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e6ca9f5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@LekoArts
LekoArts marked this pull request as ready for review March 18, 2024 12:35
@LekoArts
LekoArts requested review from brkalow and tmilewski March 18, 2024 12:35
@LekoArts

This comment was marked as outdated.

@clerk-cookie

This comment was marked as outdated.

"scripts": {
"build": "next build",
"dev": "next dev",
"dev:debug": "NEXT_PUBLIC_CLERK_ELEMENTS_DEBUG=true next dev",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

@brkalow brkalow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

left a few non-blocking comments, but lgtm! Nice work


Provider.displayName = displayName;

function useContext(allowMissingContext: boolean = false) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're not currently using this helper to enforce the context existing 🤔 Do you think we'll have a use for it in the future?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The helper is very much a copy of https://github.com/clerk/javascript/blob/f984829a70fbeae0d6faef58248ddd368a771cce/packages/elements/src/react/utils/create-context-from-actor-ref.ts so that's why it's here. I think we can keep it and then at least have a fallback error if we don't handle it ourselves

* </Loading>
* </Step>
*/
export function Loading({ children, scope }: LoadingProps) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

💭 I wonder if we could expose Loading from common and use a common loading context rendered within each flow. No action needed for now, just a thought! It would likely complicate some of the scope logic by trying to make it generic.

Comment on lines +26 to +28
throw new Error(
`You used a hook from "${Provider.displayName}" but it's not inside a <${Provider.displayName}.Provider> component.`,
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

❓ Do we have a heuristic for when we throw a ClerkElementsRuntimeError vs just Error? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think at this point it's a bit random, but we can tackle it as part of SDK-1315

@LekoArts
LekoArts enabled auto-merge (squash) March 20, 2024 14:37
@LekoArts
LekoArts merged commit d54e42d into main Mar 20, 2024
@LekoArts
LekoArts deleted the lekoarts/sdk-1291-loading-states branch March 20, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants