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

⬆️ upgrade templates #2658

Merged
merged 16 commits into from
Oct 2, 2023
Merged

⬆️ upgrade templates #2658

merged 16 commits into from
Oct 2, 2023

Conversation

zbeyens
Copy link
Member

@zbeyens zbeyens commented Sep 30, 2023

Description

See changesets.

@changeset-bot
Copy link

changeset-bot bot commented Sep 30, 2023

⚠️ No Changeset found

Latest commit: 4831be0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

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

Click here to learn what changesets are, and how to add one.

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

@vercel
Copy link

vercel bot commented Sep 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 2, 2023 8:52am

@reviewpad reviewpad bot added the large Pull request is large label Sep 30, 2023
@zbeyens
Copy link
Member Author

zbeyens commented Sep 30, 2023

@shahriar-shojib We have a single type error in the playground template:

2023-09-30 at 18 27 31

Not sure why but it's only for the caption and deserializeMd plugins.

Could you take a look? Will tip $50 for that one 🙂

@shahriar-shojib
Copy link
Collaborator

I looked into this one, and the two plugins that are not working are createCaptionPlugin and createDeserializeMdPlugin.

I have tested the same thing on www project and did not face this issue.

Anyhow, the issue is createPlugins expects PlatePlugin<AnyObject, Value, PlateEditor<Value>> and PlatePlugin<CaptionPlugin, Value, PlateEditor<Value>> was provided, however if this was the case this should occur in all other plugins.

I also noticed that each bundle is emitting its own types which should be imported from @plate/common.

Since I am not facing this issue on www leads me to believe that there are some inconsistency on the published packages, I will have to investigate further into this.

@shahriar-shojib
Copy link
Collaborator

Hello,
Hopefully creating a release from this branch will fix the issue

https://github.com/udecode/plate/tree/fix/tsup-dts-output

this does not bundle node_modules dts into the package's d.ts which should not only reduce the package size but also improve tsserver and tsc performance on the user's end and ensures all packages are referencing to a single type at a time instead of having them declared on their own package.

@zbeyens
Copy link
Member Author

zbeyens commented Oct 1, 2023

Also, Lodash issue is still here: https://bundlephobia.com/package/@udecode/[email protected]
With rollup, it was handled by

[
'import',
{
libraryName: 'lodash',
libraryDirectory: '',
camel2DashComponentName: false,
},
'lodash',
],

Any idea?

@shahriar-shojib
Copy link
Collaborator

Also, Lodash issue is still here: https://bundlephobia.com/package/@udecode/[email protected] With rollup, it was handled by

[
'import',
{
libraryName: 'lodash',
libraryDirectory: '',
camel2DashComponentName: false,
},
'lodash',
],

Any idea?

I am checking now

@shahriar-shojib
Copy link
Collaborator

I could not find a possible reason why only these two plugins fail typechecking, it seems a lot of types are still bundled into d.ts which because of implicit return types and those types being re-exported from "@plate/common" .

@shahriar-shojib
Copy link
Collaborator

type PluginCreatorFn<Options extends PluginOptions = PluginOptions> = <
  V extends Value = Value,
  E extends PlateEditor<V> = PlateEditor<V>,
>(
  override?: Partial<PlatePlugin<NoInfer<Options>, V, E>>,
  overrideByKey?: OverrideByKey<V, E>
) => PlatePlugin;

/**
 * Enables support for caption.
 */
export const createCaptionPlugin: PluginCreatorFn<CaptionPlugin> =
  createPluginFactory<CaptionPlugin>({
    key: KEY_CAPTION,
    withOverrides: withCaption,
    handlers: {
      onKeyDown: onKeyDownCaption,
    },
    options: {
      pluginKeys: [],
    },
  }) as any satisfies PluginCreatorFn<CaptionPlugin>;

is this acceptable as a temporary workaround?

@shahriar-shojib
Copy link
Collaborator

Or createPlugin's type can be relaxed

@shahriar-shojib
Copy link
Collaborator

or moving createPluginFactory and createPlugins functionality could be moved to @plate/common could fix the issue, I am not 100% sure

@zbeyens
Copy link
Member Author

zbeyens commented Oct 1, 2023

type PluginCreatorFn<Options extends PluginOptions = PluginOptions> = <
  V extends Value = Value,
  E extends PlateEditor<V> = PlateEditor<V>,
>(
  override?: Partial<PlatePlugin<NoInfer<Options>, V, E>>,
  overrideByKey?: OverrideByKey<V, E>
) => PlatePlugin;

/**
 * Enables support for caption.
 */
export const createCaptionPlugin: PluginCreatorFn<CaptionPlugin> =
  createPluginFactory<CaptionPlugin>({
    key: KEY_CAPTION,
    withOverrides: withCaption,
    handlers: {
      onKeyDown: onKeyDownCaption,
    },
    options: {
      pluginKeys: [],
    },
  }) as any satisfies PluginCreatorFn<CaptionPlugin>;

is this acceptable as a temporary workaround?

Not really, too much overhead, we need to keep type inference. I think the issue appeared because of the interface to type change for AnyObject, not sure.

Type
Partial<PlatePlugin<CaptionPlugin, Value, PlateEditor<Value>>>
is not assignable to type
void | Partial<PlatePlugin<AnyObject, Value, PlateEditor<Value>>>

so the void | is the issue.

createPlugins should return PlatePlugin<AnyObject,...>[] but

@shahriar-shojib
Copy link
Collaborator

I will investigate this further, I am surprised that it's not happening in www though.

@zbeyens
Copy link
Member Author

zbeyens commented Oct 1, 2023

www uses the local build while the templates are using the published version

@zbeyens
Copy link
Member Author

zbeyens commented Oct 1, 2023

Note that intellisense is extremely slow (and heavy CPU usage) specifically inside createPlugins (I don't think it was the case before)

2023-10-01.at.23.50.04.mp4

If you have a proposal to soften createPlugins type, let me know. Inference is probably messing up here.

# Conflicts:
#	apps/www/tsconfig.tsbuildinfo
#	config/tsup.config.ts
#	package.json
#	yarn.lock
@shahriar-shojib
Copy link
Collaborator

I will create a private registry and test out the released packages to solve the issue.
As for the tsserver being slow on createPlugins function, I think it's due to the packages bundling d.ts and each having their own types rather than importing.

@zbeyens
Copy link
Member Author

zbeyens commented Oct 2, 2023

So I've tried to create a minimal reproduction of the tsserver issue. Any array that contains any create*Plugin (created by createPluginFactory) is raising the issue. So PlatePlugin and createPlugins are fine.

I'll do a test release for the other issues in the meantime.

@zbeyens
Copy link
Member Author

zbeyens commented Oct 2, 2023

Another regression we have is #2661, more context in evanw/esbuild#622 (comment)

I'll add .js to prismjs imports, didn't find an automatic way to do it

@zbeyens zbeyens merged commit 4fa2357 into main Oct 2, 2023
8 of 9 checks passed
@zbeyens zbeyens deleted the vendor/template branch October 2, 2023 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
large Pull request is large
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants