Skip to content

Appear component does not function when placed in an MDX file #870

Open
@antonwintergerst

Description

@antonwintergerst

Describe Your Environment

What version of Spectacle are you using?
[email protected]

What version of React are you using?
[email protected]

What browser are you using?
Chrome 80.0.3987.149

What machine are you on?
MacBook Pro (15-inch 2017)

Describe the Problem

Appear component does not function when placed in an MDX file.

Expected behavior:
Slide navigation should step through Appear steps before moving to next slide.

Actual behavior:
Slide navigation skips Appear steps and moves to next slide.

Additional Information

These were the steps I took to setup a project:

  1. Install global dependencies
    npm i typescript spectacle-cli -g

  2. Create a new presentation
    spectacle-boilerplate --mode mdx --dir "some-presentation"

  3. Add TypeScript support

yarn add typescript @babel/plugin-proposal-class-properties @babel/preset-env @babel/preset-typescript -D
tsc --init --declaration --allowSyntheticDefaultImports --target esnext --outDir lib
  1. Add a .babelrc file
{
  "presets": ["@babel/env", "@babel/typescript", "@babel/preset-react"],
  "plugins": ["@babel/proposal-class-properties"]
}
  1. Update webpack.config.js
// Add this to module.exports
resolve: {
    extensions: ['.ts', '.tsx', '.js', '.json']
}
// Change test: /\.(jsx)?$/, to
test: /\.(ts|js)x?$/,

How was I able to even render an Appear component in MDX?

By updating the mdxComponentMap to include the Appear tag and then mapping this to the Appear component:

const Presentation = () => (
  <MDXProvider
    components={{
      ...mdxComponentMap,
      Appear: props => <Appear {...props} />
    }}
  >
    <Deck loop theme={theme} template={template}>
      {slides
        .map((MDXSlide, i) => [MDXSlide, notes[i]])
        .map(([MDXSlide, MDXNote], i) => (
          <Slide key={`slide-${i}`} slideNum={i}>
            <MDXSlide />
            <Notes>
              <MDXNote />
            </Notes>
          </Slide>
        ))}
    </Deck>
  </MDXProvider>
);

This allows markdown to be written like so:

<Appear elementNum={1}>

- Lorem ipsum
- Lorem ipsum
- Lorem ipsum

</Appear>

And it is correctly rendering the expected HTML

<div style="opacity: 0;">
  <ul color="primary" font-family="text" font-size="text" class="sc-bZQynM fHBYr">
    <li class="sc-gzVnrw eGyYYk">Lorem ipsum</li>
    <li class="sc-gzVnrw eGyYYk">Lorem ipsum</li>
    <li class="sc-gzVnrw eGyYYk">Lorem ipsum</li>
  </ul>
</div>

However, the component is not detected by the searchChildrenForAppear function and this results in the navigator not being able to step through these Appear steps. Here's where that function gets called:

const appearElements = searchChildrenForAppear(slide.props.children);

Any assistance would be greatly appreciated 🙌

Metadata

Metadata

Assignees

Labels

✓ VerifiedOrg member or multiple community members can reproduce a given bug🐛 BugIssues or PRs that report or fix a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions