Patches Welcome #6: A Colon in a Story Name Broke Widgetbook's Entire Canvas
Stories with a colon in the name don't render on web. You click the story, the canvas stays on "Welcome to Widgetbook", and nothing errors. No crash, no red text. The component just isn't there. The report Is
Stories with a colon in the name don't render on web. You click the story, the canvas stays on "Welcome to Widgetbook", and nothing errors. No crash, no red text. The component just isn't there.
The report
Issue #2059. A developer had a story named Profile (tap: Accept). Worked fine on desktop. On web, the canvas stayed blank. Every story without a colon rendered normally.
Why colons break paths on web
Widgetbook builds navigation paths by joining story names with package:path's p.join. On native platforms, p.join uses POSIX rules. On web, it uses URL rules. That's the trap.
URL path semantics treat a colon as a scheme separator. p.url.join('Folder/Component', 'Profile (tap: Accept)') sees tap: as a URI scheme and drops the parent segment entirely:
p.url.join('Folder/Component', 'Profile (tap: Accept)');
// โ 'Profile (tap: Accept)' โ parent gone
p.posix.join('Folder/Component', 'Profile (tap: Accept)');
// โ 'Folder/Component/Profile (tap: Accept)' โ correct
The navigation tree builds with the wrong path, the router can't resolve it, and the canvas falls back to the welcome screen. No error because it's a valid path lookup that returns nothing.
The fix
Replace p.join / p.split with p.posix.join / p.posix.split in the five runtime files that build and resolve story paths: component.dart, scenario.dart, story.dart, tree.dart, tree_node.dart. Import narrowed to show posix so nobody drifts back to the default context.
86 lines added, 12 deleted. Most of that is tests: colon_in_path_test.dart with five cases covering Component.fullPath, Story.path, Scenario.path, TreeNode.path, and TreeNode.findByPath.
The part that's subtle
package:path doing platform detection on web is documented behaviour. It's not a bug in the library. The issue is that Widgetbook's navigation paths are logical paths, not URLs, so they should never have been built with URL semantics regardless of which platform the code runs on. POSIX is the right context because these paths never hit a URL parser. The colon just made the mismatch visible.
What I couldn't test
I confirmed the fix on Chrome and in the test suite, but I didn't test Safari or Firefox. The package:path platform detection should be identical across browsers (it keys on dart.library.html, not the user agent), but I haven't verified that personally.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.