-
Notifications
You must be signed in to change notification settings - Fork 9
Storybook webpack to vite, add config helpers #260
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
Closed
crysadrak
wants to merge
6
commits into
mjancarik:migrate-2-changesets
from
crysadrak:storybook-webpack-2-vite
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
11750e5
feat(@merkur/preact)!: remove webpack export and related peer depende…
d78c619
feat: 🎸 feat(tool-storybook): add vanilla JS support and preview conf…
092c03e
fix: 🐛 stabilize widget lifecycle, renderer, and input validation
21aa6b5
Escape ErrorView data
9befa68
Fix readme, jsdoc, integration doc
3fdcd42
Fix es11, and add changesets for storybook webpack 2 to vite migration
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,9 @@ | ||
| --- | ||
| "@merkur/preact": major | ||
| --- | ||
|
|
||
| Remove the `./webpack` subpath export and its associated peer dependencies. | ||
|
|
||
| - **What** The `@merkur/preact/webpack` subpath export has been deleted. The peer dependencies `@merkur/tool-webpack`, `babel-loader`, and `@babel/preset-react` are no longer declared or required by this package. | ||
| - **Why** Webpack-based tooling was superseded by the Vite/esbuild pipeline. Maintaining a parallel Webpack integration added complexity and prevented simplifying the package's dependency surface. Removing it reduces install size and eliminates the need to keep Babel peer deps in sync. | ||
| - **How** Replace any import from `@merkur/preact/webpack` with the Vite/Storybook-based equivalent provided by `@merkur/tool-storybook`. Remove `@merkur/tool-webpack`, `babel-loader`, and `@babel/preset-react` from your project's dependencies if they were pulled in solely for Merkur's Webpack integration. |
This file contains hidden or 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,9 @@ | ||
| --- | ||
| "@merkur/tool-storybook": minor | ||
| --- | ||
|
|
||
| Add vanilla JS widget support and preview configuration helpers to Storybook tooling. | ||
|
|
||
| - **What** New `createPreviewConfig` helper provides a simplified Storybook `preview.js` setup with automatic widget name/version validation. New `createVanillaRenderer` enables rendering vanilla JavaScript widgets inside Storybook stories; a per-widget WeakMap ensures isolated state across concurrent stories. `createWidgetLoader` now correctly unmounts the previous widget before mounting a new one when switching stories, preserves `state`/`props` keys not present in story args, and supports both `setProps` and `setState` widget APIs. All exported functions are documented with comprehensive JSDoc. Fixed ES11 module format issues that prevented the package from being consumed in certain build pipelines. | ||
| - **Why** Previously only Preact-based widgets had first-class Storybook support. Vanilla JS widgets had no renderer, forcing teams to wire up lifecycle management by hand. The missing `createPreviewConfig` abstraction caused boilerplate duplication across projects, and the lifecycle bugs in `createWidgetLoader` led to stale widget instances between story navigations. | ||
| - **How** No breaking changes. Opt in to the new helpers by importing them from `@merkur/tool-storybook`. Use `createPreviewConfig({ name, version })` in `.storybook/preview.js` and `createVanillaRenderer()` as the story renderer for vanilla widgets. |
This file contains hidden or 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,9 @@ | ||
| --- | ||
| "@merkur/create-widget": patch | ||
| --- | ||
|
|
||
| Fix vanilla ErrorView template to use correct HTML attribute and prevent XSS. | ||
|
|
||
| - **What** The generated `ErrorView` template in the vanilla widget scaffold used the JSX attribute `className` instead of the HTML attribute `class`, causing the CSS class to be silently dropped. Additionally, interpolated values (`status`, `message`, `stack`) were injected raw into the HTML string, opening a cross-site scripting (XSS) vulnerability. | ||
| - **Why** Vanilla templates are plain HTML strings — not JSX — so `className` is not interpreted. Raw interpolation of untrusted error data (e.g. a server-side message) could allow script injection in any app that renders the error view. | ||
| - **How** Nothing. |
16 changes: 12 additions & 4 deletions
16
packages/create-widget/views/vanilla/template/src/views/ErrorView.js
This file contains hidden or 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 |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| function escHtml(s) { | ||
| return String(s) | ||
| .replace(/&/g, '&') | ||
| .replace(/</g, '<') | ||
| .replace(/>/g, '>') | ||
| .replace(/"/g, '"'); | ||
| } | ||
|
|
||
| export default function ErrorView(widget) { | ||
| return ` | ||
| <div className='merkur__error'> | ||
| <h1>Status: ${widget.error.status}</h1> | ||
| <h2>Message: ${widget.error.message}</h2> | ||
| <pre>${widget.error.stack}</pre> | ||
| <div class='merkur__error'> | ||
| <h1>Status: ${escHtml(widget.error.status)}</h1> | ||
| <h2>Message: ${escHtml(widget.error.message)}</h2> | ||
| <pre>${escHtml(widget.error.stack)}</pre> | ||
| </div> | ||
| `; | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,5 +2,4 @@ | |
| !cli/**/* | ||
| !lib/**/* | ||
| !entries/**/* | ||
| !webpack/**/* | ||
| !package.json | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,51 +1,75 @@ | ||
| <p align="center"> | ||
| <a href="https://merkur.js.org/docs/getting-started" title="Getting started"> | ||
| <img src="https://raw.githubusercontent.com/mjancarik/merkur/master/images/merkur-logo.png" width="100px" height="100px" alt="Merkur illustration"/> | ||
| </a> | ||
| </p> | ||
|
|
||
| # Merkur | ||
| # @merkur/preact | ||
|
|
||
| [](https://github.com/mjancarik/merkur/actions/workflows/ci.yml) | ||
| [](https://www.npmjs.com/package/@merkur/core) | ||
|  | ||
| [](https://www.npmjs.com/package/@merkur/preact) | ||
|  | ||
| [](https://github.com/prettier/prettier) | ||
|
|
||
| The [Merkur](https://merkur.js.org/) is tiny extensible javascript library for front-end microservices(micro frontends). It allows by default server side rendering for loading performance boost. You can connect it with other frameworks or languages because merkur defines easy API. You can use one of six predefined template's library [Preact](https://preactjs.com/), [µhtml](https://github.com/WebReflection/uhtml#readme), [Svelte](https://svelte.dev/) and [vanilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) but you can easily extend for others. | ||
|
|
||
| ## Features | ||
| - Flexible templating engine | ||
| - Usable with all tech stacks | ||
| - SSR-ready by default | ||
| - Easy extensible with plugins | ||
| - Tiny - 1 KB minified + gzipped | ||
| Preact integration helpers for [Merkur](https://merkur.js.org/) widgets. Provides client and server entry points, rendering helpers, and CLI scaffolding support for Preact-based Merkur widgets. | ||
|
|
||
| ## Getting started | ||
| ## Installation | ||
|
|
||
| ```bash | ||
| npx @merkur/create-widget <name> | ||
| npm install @merkur/preact | ||
| ``` | ||
|
|
||
| cd name | ||
| Peer dependencies required: | ||
|
|
||
| npm run dev // Point your browser at http://localhost:4444/ | ||
| ```bash | ||
| npm install @merkur/core @merkur/plugin-component | ||
| ``` | ||
|  | ||
| ## Documentation | ||
|
|
||
| To check out [live demo](https://merkur.js.org/demo) and [docs](https://merkur.js.org/docs), visit [https://merkur.js.org](https://merkur.js.org). | ||
| ## Exports | ||
|
|
||
| ## Contribution | ||
| | Export | Description | | ||
| |--------|-------------| | ||
| | `@merkur/preact/client` | Client-side Preact rendering helpers | | ||
| | `@merkur/preact/server` | Server-side rendering helpers (uses `preact-render-to-string`) | | ||
| | `@merkur/preact/entries/client.js` | Preact client widget entry point | | ||
| | `@merkur/preact/entries/server.js` | Preact server widget entry point | | ||
| | `@merkur/preact/cli` | CLI helpers for widget scaffolding | | ||
|
|
||
| Contribute to this project via [Pull-Requests](https://github.com/mjancarik/merkur/pulls). | ||
| ## Documentation | ||
|
|
||
| We are using [Changesets](https://github.com/changesets/changesets) for versioning and releasing. To add a changeset describing your changes, run `npm run changeset` from the root of the monorepo. | ||
| Full documentation and setup guide at [merkur.js.org](https://merkur.js.org/docs/getting-started). | ||
|
|
||
| ## Breaking Changes | ||
|
|
||
| ### v0.47.0 | ||
|
|
||
| The `@merkur/preact/webpack` export (`applyBabelLoader`, `applyPreactConfig`) has been **removed**, along with the `@babel/preset-react`, `@merkur/tool-webpack`, and `babel-loader` peer dependencies. | ||
|
|
||
| If your webpack config used these helpers, configure the Preact Babel preset manually: | ||
|
|
||
| ```javascript | ||
| // webpack.config.js | ||
| module.exports = { | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.(js|ts|tsx|jsx|mjs)$/, | ||
| exclude: /node_modules/, | ||
| use: { | ||
| loader: 'babel-loader', | ||
| options: { | ||
| presets: [ | ||
| [ | ||
| '@babel/preset-react', | ||
| { runtime: 'automatic', importSource: 'preact' }, | ||
| ], | ||
| ], | ||
| }, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
| ``` | ||
|
|
||
| > **Note:** The release process and [changeset format](https://github.com/mjancarik/merkur#changeset-format) are documented in the [root README](https://github.com/mjancarik/merkur#contribution), which is the source of truth for all contribution and release guidelines. | ||
| Alternatively, migrate to the Vite-based Storybook setup described in the [Storybook integration guide](https://merkur.js.org/docs/storybook-integration-into-merkur), which no longer requires webpack or Babel configuration. | ||
|
|
||
| --- | ||
| ## Contribution | ||
|
|
||
| Thank you to all the people who already contributed to Merkur! | ||
| Contribute via [Pull-Requests](https://github.com/mjancarik/merkur/pulls). | ||
|
|
||
| <a href="https://github.com/mjancarik/merkur/graphs/contributors"> | ||
| <img src="https://contrib.rocks/image?repo=mjancarik/merkur" /> | ||
| </a> | ||
| We use [Changesets](https://github.com/changesets/changesets) for versioning. Run `npm run changeset` from the monorepo root to add a changeset for your changes. | ||
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| const defaultConfig = require('../../jest.config.js'); | ||
|
|
||
| module.exports = { ...defaultConfig }; | ||
| module.exports = { ...defaultConfig, testEnvironment: 'jsdom' }; |
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.
Shouldn't this be in a changeset instead of README?
I guess the version does not match anymore either, but if we put it in the changeset, it will be always correct.