-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
SolidJS framework feedback #20584
Closed
Closed
SolidJS framework feedback #20584
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4f92c5d
Initial SolidJS framework scaffolding
webblocksapp d6055f7
Updated preset with vite-plugin-solid
webblocksapp 1c7fa8e
Added solid renderer boilerplate
webblocksapp 5b71882
Added solid as repro-template
webblocksapp f208284
Registered new generator for Solid
webblocksapp cfc1551
Fixed solid storybook auto migration error
webblocksapp f9ad586
Configured solid sandbox for further development
webblocksapp ce9113a
Initial Button component as SolidJS template
webblocksapp 8b64fbd
Solid renderer definition
webblocksapp e157e03
Working Solid render initial prototype.
webblocksapp 2ccf69d
Changed store structure for story context.
webblocksapp 57d8f45
Added fine grained updates engine.
webblocksapp b1ed4a0
solid renderer tsup config for dev. WIP
webblocksapp 17a701e
Merge remote-tracking branch 'upstream/next' into solid-js-framework
webblocksapp 01c6384
Clean api definition for intercepting story props.
webblocksapp 80d025f
Refactored reactivity with a decorator. Removed args mapper.
webblocksapp bf6dc7f
Updated minor patch versions.
webblocksapp ff32212
Refactored story context mapping.
webblocksapp 8642a22
Added remount logic for globals at render.tsx
webblocksapp 90ad0f1
Merge remote-tracking branch 'upstream/next' into solid-js-framework
webblocksapp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Storybook for SolidJS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"name": "@storybook/solid-vite", | ||
"version": "7.0.0-beta.26", | ||
"description": "Storybook for SolidJS and Vite: Develop SolidJS in isolation with Hot Reloading.", | ||
"keywords": [ | ||
"storybook" | ||
], | ||
"homepage": "https://github.com/storybookjs/storybook/tree/main/frameworks/solid-vite", | ||
"bugs": { | ||
"url": "https://github.com/storybookjs/storybook/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/storybookjs/storybook.git", | ||
"directory": "frameworks/solid-vite" | ||
}, | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/storybook" | ||
}, | ||
"license": "MIT", | ||
"exports": { | ||
".": { | ||
"node": "./dist/index.js", | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts" | ||
}, | ||
"./preset": { | ||
"require": "./dist/preset.js", | ||
"import": "./dist/preset.mjs", | ||
"types": "./dist/preset.d.ts" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/**/*", | ||
"template/**/*", | ||
"README.md", | ||
"*.js", | ||
"*.d.ts" | ||
], | ||
"scripts": { | ||
"check": "tsc --noEmit", | ||
"prep": "../../../scripts/prepare/bundle.ts" | ||
}, | ||
"dependencies": { | ||
"@storybook/addons": "7.0.0-beta.26", | ||
"@storybook/builder-vite": "7.0.0-beta.26", | ||
"@storybook/channel-postmessage": "7.0.0-beta.26", | ||
"@storybook/channel-websocket": "7.0.0-beta.26", | ||
"@storybook/client-api": "7.0.0-beta.26", | ||
"@storybook/core-server": "7.0.0-beta.26", | ||
"@storybook/node-logger": "7.0.0-beta.26", | ||
"@storybook/preview-web": "7.0.0-beta.26", | ||
"@storybook/solid": "7.0.0-beta.26", | ||
"magic-string": "^0.26.1", | ||
"vite-plugin-solid": "^2.5.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^16.0.0", | ||
"typescript": "~4.9.3" | ||
}, | ||
"engines": { | ||
"node": "^14.18 || >=16" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"bundler": { | ||
"entries": [ | ||
"./src/index.ts", | ||
"./src/preset.ts" | ||
], | ||
"platform": "node" | ||
}, | ||
"gitHead": "6559b419625c2dcf76bad1a12fcf75e3dd7c4187" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/preset'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type { StorybookConfig } from '@storybook/builder-vite'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { hasVitePlugins, StorybookConfig } from '@storybook/builder-vite'; | ||
|
||
export const core: StorybookConfig['core'] = { | ||
builder: '@storybook/builder-vite', | ||
renderer: '@storybook/solid', | ||
}; | ||
|
||
export const viteFinal: StorybookConfig['viteFinal'] = async (config, { presets }) => { | ||
const { plugins = [] } = config; | ||
|
||
// Add solid plugin if not present | ||
if (!(await hasVitePlugins(plugins, ['vite-plugin-solid']))) { | ||
const { default: solidPlugin } = await import('vite-plugin-solid'); | ||
plugins.push(solidPlugin()); | ||
} | ||
|
||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"types": ["node"], | ||
"resolveJsonModule": true | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["src/**/*.test.*", "src/**/__testfixtures__/**"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { baseGenerator } from '../baseGenerator'; | ||
import type { Generator } from '../types'; | ||
|
||
const generator: Generator = async (packageManager, npmOptions, options) => { | ||
await baseGenerator(packageManager, npmOptions, options, 'solid'); | ||
}; | ||
|
||
export default generator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,8 +154,17 @@ export class StoryRender<TRenderer extends Renderer> implements Render<TRenderer | |
if (!this.story) throw new Error('cannot render when not prepared'); | ||
if (!canvasElement) throw new Error('cannot render when canvasElement is unset'); | ||
|
||
const { id, componentId, title, name, tags, applyLoaders, unboundStoryFn, playFunction } = | ||
this.story; | ||
const { | ||
id, | ||
componentId, | ||
title, | ||
name, | ||
tags, | ||
applyLoaders, | ||
unboundStoryFn, | ||
playFunction, | ||
prepareContext: prepareStoryContext, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's no reason to rename this to |
||
} = this.story; | ||
|
||
if (forceRemount && !initial) { | ||
// NOTE: we don't check the cancel actually worked here, so the previous | ||
|
@@ -181,15 +190,15 @@ export class StoryRender<TRenderer extends Renderer> implements Render<TRenderer | |
return; | ||
} | ||
|
||
const renderStoryContext: StoryContext<TRenderer> = { | ||
const renderStoryContext: StoryContext<TRenderer> = prepareStoryContext({ | ||
...loadedContext!, | ||
// By this stage, it is possible that new args/globals have been received for this story | ||
// and we need to ensure we render it with the new values | ||
...this.storyContext(), | ||
abortSignal, | ||
// We should consider parameterizing the story types with TRenderer['canvasElement'] in the future | ||
canvasElement: canvasElement as any, | ||
}; | ||
}); | ||
const renderContext: RenderContext<TRenderer> = { | ||
componentId, | ||
title, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -71,23 +71,10 @@ export function prepareStory<TRenderer extends Renderer>( | |||||||||||||
}; | ||||||||||||||
|
||||||||||||||
const undecoratedStoryFn: LegacyStoryFn<TRenderer> = (context: StoryContext<TRenderer>) => { | ||||||||||||||
const mappedArgs = Object.entries(context.args).reduce((acc, [key, val]) => { | ||||||||||||||
const mapping = context.argTypes[key]?.mapping; | ||||||||||||||
acc[key] = mapping && val in mapping ? mapping[val] : val; | ||||||||||||||
return acc; | ||||||||||||||
}, {} as Args); | ||||||||||||||
|
||||||||||||||
const includedArgs = Object.entries(mappedArgs).reduce((acc, [key, val]) => { | ||||||||||||||
const argType = context.argTypes[key] || {}; | ||||||||||||||
if (includeConditionalArg(argType, mappedArgs, context.globals)) acc[key] = val; | ||||||||||||||
return acc; | ||||||||||||||
}, {} as Args); | ||||||||||||||
|
||||||||||||||
const includedContext = { ...context, args: includedArgs }; | ||||||||||||||
const { passArgsFirst: renderTimePassArgsFirst = true } = context.parameters; | ||||||||||||||
return renderTimePassArgsFirst | ||||||||||||||
? (render as ArgsStoryFn<TRenderer>)(includedContext.args, includedContext) | ||||||||||||||
: (render as LegacyStoryFn<TRenderer>)(includedContext); | ||||||||||||||
? (render as ArgsStoryFn<TRenderer>)(context.args, context) | ||||||||||||||
: (render as LegacyStoryFn<TRenderer>)(context); | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
// Currently it is only possible to set these globally | ||||||||||||||
|
@@ -109,8 +96,13 @@ export function prepareStory<TRenderer extends Renderer>( | |||||||||||||
if (!render) throw new Error(`No render function available for storyId '${id}'`); | ||||||||||||||
|
||||||||||||||
const decoratedStoryFn = applyHooks<TRenderer>(applyDecorators)(undecoratedStoryFn, decorators); | ||||||||||||||
const unboundStoryFn = (context: StoryContext<TRenderer>) => { | ||||||||||||||
const unboundStoryFn = (context: StoryContext<TRenderer>) => decoratedStoryFn(context); | ||||||||||||||
|
||||||||||||||
// This function is invoked at StoryRender.ts, with this | ||||||||||||||
// the context is prepared before invoking the render function. | ||||||||||||||
Comment on lines
+101
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
const prepareContext = (context: StoryContext<TRenderer>) => { | ||||||||||||||
let finalContext: StoryContext<TRenderer> = context; | ||||||||||||||
|
||||||||||||||
if (global.FEATURES?.argTypeTargetsV7) { | ||||||||||||||
const argsByTarget = groupArgsByTarget(context); | ||||||||||||||
finalContext = { | ||||||||||||||
|
@@ -121,7 +113,19 @@ export function prepareStory<TRenderer extends Renderer>( | |||||||||||||
}; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return decoratedStoryFn(finalContext); | ||||||||||||||
const mappedArgs = Object.entries(finalContext.args).reduce((acc, [key, val]) => { | ||||||||||||||
const mapping = finalContext.argTypes[key]?.mapping; | ||||||||||||||
acc[key] = mapping && val in mapping ? mapping[val] : val; | ||||||||||||||
return acc; | ||||||||||||||
}, {} as Args); | ||||||||||||||
|
||||||||||||||
const includedArgs = Object.entries(mappedArgs).reduce((acc, [key, val]) => { | ||||||||||||||
const argType = finalContext.argTypes[key] || {}; | ||||||||||||||
if (includeConditionalArg(argType, mappedArgs, finalContext.globals)) acc[key] = val; | ||||||||||||||
return acc; | ||||||||||||||
}, {} as Args); | ||||||||||||||
|
||||||||||||||
return { ...finalContext, args: includedArgs }; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
const play = storyAnnotations?.play || componentAnnotations.play; | ||||||||||||||
|
@@ -150,6 +154,7 @@ export function prepareStory<TRenderer extends Renderer>( | |||||||||||||
unboundStoryFn, | ||||||||||||||
applyLoaders, | ||||||||||||||
playFunction, | ||||||||||||||
prepareContext, | ||||||||||||||
}; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"rules": { | ||
"import/extensions": "off", | ||
"react/react-in-jsx-scope": "off", | ||
"import/no-extraneous-dependencies": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Storybook SolidJS Renderer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const path = require('path'); | ||
const baseConfig = require('../../jest.config.browser'); | ||
|
||
module.exports = { | ||
...baseConfig, | ||
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this, as no one will be migrating from an old solid setup because that doesn't exist.