Skip to content

Commit

Permalink
Filter out storybooks in CoreGui (#220)
Browse files Browse the repository at this point in the history
# Problem
When opening flipbook several warnings appear in the output from it
attempting to load Roblox-created storybooks in CoreGui
```
  12:37:42.545  Failed to load storybook CoreGui.RobloxGui.Modules.VoiceChatPrompt.VoiceChatPrompt.storybook. Error: table expected, got nil  -  Edit - useStorybooks:40
  12:37:42.545  Failed to load storybook CoreGui.RobloxGui.Modules.Settings.Settings.storybook. Error: table expected, got nil  -  Edit - useStorybooks:40
  12:37:42.545  Failed to load storybook CoreGui.RobloxGui.Modules.InGameChat.BubbleChat.BubbleChat.storybook. Error: table expected, got nil  -  Edit - useStorybooks:40
  12:37:42.545  Failed to load storybook CoreGui.RobloxGui.Modules.TopBar.TopBar.storybook. Error: table expected, got nil  -  Edit - useStorybooks:40
  12:37:42.545  Failed to load storybook CoreGui.RobloxGui.Modules.ContactList.ContactList.storybook. Error: table expected, got nil  -  Edit - useStorybooks:40
```

# Solution

To fix this, I've updated `isStorybookModule` to return `false` for any
storybook in CoreGui

Closes #218 

# Checklist

- [x] Ran `./bin/test.sh` locally before merging

---------

Co-authored-by: pashleyy <[email protected]>
  • Loading branch information
vocksel and passhley authored Nov 19, 2023
1 parent 2902c1b commit fa5861d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Story/isStorybookModule.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
local flipbook = script:FindFirstAncestor("flipbook")

local CoreGui = game:GetService("CoreGui")

local constants = require(flipbook.constants)

local function isStorybookModule(instance: Instance): boolean
return instance:IsA("ModuleScript") and instance.Name:match(constants.STORYBOOK_NAME_PATTERN) ~= nil
return instance:IsA("ModuleScript")
and instance.Name:match(constants.STORYBOOK_NAME_PATTERN) ~= nil
and not instance:IsDescendantOf(CoreGui)
end

return isStorybookModule
12 changes: 12 additions & 0 deletions src/Story/isStorybookModule.spec.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
return function()
local CoreGui = game:GetService("CoreGui")

local isStorybookModule = require(script.Parent.isStorybookModule)

it("should return true for ModuleScripts with the .storybook extension", function()
Expand Down Expand Up @@ -28,4 +30,14 @@ return function()

expect(isStorybookModule(storybook)).to.equal(false)
end)

it("should return false for storybooks in CoreGui", function()
local storybook = Instance.new("ModuleScript")
storybook.Name = "Foo.storybook"
storybook.Parent = CoreGui

expect(isStorybookModule(storybook)).to.equal(false)

storybook:Destroy()
end)
end
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exclude = ["*"]
[dependencies]
Roact = "roblox/[email protected]"
React = "jsdotlua/[email protected]"
ReactRoblox = "jsdotlua/[email protected].1"
ReactRoblox = "jsdotlua/[email protected].2"
Sift = "csqrl/[email protected]"
t = "osyrisrblx/[email protected]"
ModuleLoader = "flipbook-labs/[email protected]"
Expand Down

0 comments on commit fa5861d

Please sign in to comment.