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

why first selector was modified? #16

Open
HytonightYX opened this issue Apr 6, 2022 · 1 comment
Open

why first selector was modified? #16

HytonightYX opened this issue Apr 6, 2022 · 1 comment

Comments

@HytonightYX
Copy link

Work with styled-component v5, and I found that first selector will be modified, and this made the whole page's style broken.

image

Here is my test code

export function addCssScope(scopes: string[]) {
  // FORM:
  // https://github.com/Andarist/stylis-plugin-extra-scope/blob/master/src/index.js
  const extraScopePlugin: StylisPlugin = (context, content, selectors) => {
    if (context === -2) {
      console.log('[selectors]', selectors);
      console.log('[content]  ', content);
      console.log('\n\n');
      return;
    }

    if (context !== -1) {
      return;
    }

    console.log('[before] selectors', selectors);

    const selector = selectors[0];
    selectors[0] = `.${scopes[0]} ${selector}`;

    for (let i = 1; i < scopes.length; i++) {
      selectors.push(`.${scopes[i]} ${selector}`);
    }

    console.log('[after] selectors', selectors);
  };

  Object.defineProperty(extraScopePlugin, 'name', {
    value: 'addCssScopePlugin',
  });

  return extraScopePlugin;
}

<StyleSheetManager target={container} stylisPlugins={plugins}>
  // .......
</StyleSheetManager>
@ToanKim
Copy link

ToanKim commented Sep 8, 2022

I'm experiencing the same issue, have you found any ideas why?

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

No branches or pull requests

2 participants